Seite 46 von 340 ErsteErste ... 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 96 146 ... LetzteLetzte
Zeige Ergebnis 1.351 bis 1.380 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; np This should be possible, shouldn't it? Errormessage: line 130: Constant expression expected. Line 130: artist_entry artist_list[num_artists]; I get that ...

  
  1. #1351
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    np

    This should be possible, shouldn't it? Errormessage: line 130: Constant expression expected.

    Line 130:
    artist_entry artist_list[num_artists];

    I get that error when compiling with visual c++. I have done the same with gcc without problems!



  2. #1352
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Raphael
    But headus is right there. The last part in the for loop is executed at the end, therefore it doesn't matter if the increment is prefixed or postfixed. You can easily try that by doing
    Code:
    for (i=0;i<3;++i) printf("%i,", i);
    and it will print 0,1,2,
    then you can also try that to get absolutely sure that the stuff in the last part is executed AFTER the loop, by inserting another printf("++"); before the ++i. The output will now be 0,++1,++2,++
    Thanks Raphael.

  3. #1353
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    np

    This should be possible, shouldn't it? Errormessage: line 130: Constant expression expected.

    Line 130:
    artist_entry artist_list[num_artists];

    I get that error when compiling with visual c++. I have done the same with gcc without problems!
    Is num_artists a define or a variable? The latter won't work. If the size is not known at compile time, you need to dynamically malloc an array.
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  4. #1354
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    That's wierd; Using gcc this alsways worked. However I got more difficult errors:

    line 158: '=': 'void *' cennot be converted in 'char **'

    Code:
    	typedef struct {
    		char * name;
    		int num_albums;
    		char ** albums;
    	} artist_entry;
    
    	artist_entry * artist_list;
    	artist_list = (artist_entry *)malloc(num_artists*sizeof(artist_entry));
    
    	for(i=0; i<num_artists; i++)
    	{
    		[...]
    line 158:	artist_list[i].albums = malloc( num_albums*sizeof(char*) );
    		[...]
    	}

  5. #1355
    AKA Homer
    Points: 12.596, Level: 73
    Level completed: 37%, Points required for next Level: 254
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Sweden
    Beiträge
    1.779
    Points
    12.596
    Level
    73
    Downloads
    0
    Uploads
    0

    Standard

    Pretty sure you'd have to write it like this:
    Code:
    artist_list[i].albums = (char **)malloc( num_albums*sizeof(char**) );


    Click Here if you want a Winamp Currently Playing Userbar like the one above.

  6. #1356
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von homer
    Pretty sure you'd have to write it like this:
    Code:
    artist_list[i].albums = (char **)malloc( num_albums*sizeof(char**) );
    Well, it should be
    Code:
    artist_list[i].albums = (char **)malloc( num_albums*sizeof(char*) );
    but that's the same since sizeof(char*) = sizeof(char**) ;p
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  7. #1357
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Ok, thanks, compiling works now, but I get wierd errors; I read a string from a file and send it to the PSP where I then decode it. Now that I found out that you can send structs via TCP I want to do the decoding-work on the server. I use exactly the same code, but it just doesn't work on the server!

    Server code:
    Code:
    	pFile = fopen ( "artists.txt" , "rb" );
    	fseek (pFile , 0 , SEEK_END);
    	lSize = ftell (pFile);
    	rewind (pFile);
    	buffer = (char*) malloc (lSize); 
    	fread (buffer,1,lSize,pFile);
    	fclose (pFile);
    
    	memcpy(num_artists_c, &buffer, 5);
    	num_artists_c[5]='\0';
    	offset = 5;
    	printf("%s\n", num_artists_c);
    	printf("num artists: %d\n", atoi(num_artists_c));
    	num_artists = atoi(num_artists_c);
    	artist_entry * artist_list;
    	artist_list = (artist_entry *)malloc(num_artists*sizeof(artist_entry));
    Output is:

    êO1
    num artists: 0
    -= Double Post =-

    I fixed it using strncopy (which sucks... but works! :)). However the serverprogram crashes with an adress-error:

    Code:
    	int i,j;
    	for(i=0; i<num_artists; i++)
    	{
    		// get artist- and album-data, works
    		artist_list[i].num_albums = num_albums;
    
    		artist_list[i].name = (char*)malloc(artist_name_lenght+1);
    		strcpy(artist_list[i].name, artist_name);
    		artist_list[i].name[artist_name_lenght]='\0';
    
    		artist_list[i].albums = (char **)malloc( num_albums*sizeof(char**) );
    
    		for(j=1;j<=num_albums;j++)
    		{
    			// get album-name, works
    			artist_list[i].albums[j] = (char*)malloc(album_name_length+1);
    			strcpy(artist_list[i].albums[j], album_name);
    			artist_list[i].albums[j][album_name_length]='\0';
    		}
    	}
    Everything works when I have these lines commented.
    Geändert von Lukeson (10-16-2006 um 01:31 PM Uhr) Grund: Automerged Doublepost

  8. #1358
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    I fixed it using strncopy (which sucks... but works! :)). However the serverprogram crashes with an adress-error:

    Code:
    	int i,j;
    	for(i=0; i<num_artists; i++)
    	{
    		// get artist- and album-data, works
    		artist_list[i].num_albums = num_albums;
    
    		artist_list[i].name = (char*)malloc(artist_name_lenght+1);
    		strcpy(artist_list[i].name, artist_name);
    		artist_list[i].name[artist_name_lenght]='\0';
    
    		artist_list[i].albums = (char **)malloc( num_albums*sizeof(char**) );
    
    		for(j=1;j<=num_albums;j++)
    		{
    			// get album-name, works
    			artist_list[i].albums[j] = (char*)malloc(album_name_length+1);
    			strcpy(artist_list[i].albums[j], album_name);
    			artist_list[i].albums[j][album_name_length]='\0';
    		}
    	}
    Everything works when I have these lines commented.
    for(j=1;j<=num_albums;j++ ) counts from 1 to num_albums, but the albums array goes from 0 to num_albums-1
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  9. #1359
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    I keep getting mixed answers on this, but you can assign multiple variables to one value with use of multiple = signs...

    Code:
    int var1, var2, var3;
    
    var1=var2=var3=123;
    
    printf("%i%i%i",var1,var2,var3
    That returns each var as '123'. Why is it some say it will only set var1 to 123?

    Just thought Id ask why some may get confused, is it differ in C++ or are the people just... out of it.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  10. #1360
    AKA Homer
    Points: 12.596, Level: 73
    Level completed: 37%, Points required for next Level: 254
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Sweden
    Beiträge
    1.779
    Points
    12.596
    Level
    73
    Downloads
    0
    Uploads
    0

    Standard

    That will set var3 to 123, var2 to var3(123) and var1 to var2(123).
    Nothing strange about that...


    Click Here if you want a Winamp Currently Playing Userbar like the one above.

  11. #1361
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    I already know that ;) Im saying, Zetta thought other wise... Not to point fingers I mean, im just saying, does C++ not allow this or what? Im just curious.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  12. #1362
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    It does. So what's the problem if some don't know this? Some at some point don't know how to avoid a loop being infinitely allocating memory, but they will learn. It would be different if there were a huge group of people claiming that & is not an operator, but a conjunctor and therefore insisting that C and C++ have bugs.
    Also giving names with that is hugely childish (even when saying your not wanting to point fingers... sarcasm is no protection). You better edit your post.
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  13. #1363
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Ya, a simple yes or no answer was all I needed Raphael. Excuse me for wanting to clairfy an answer to a question and getting bashed for it. Sometimes I think you act childish Raphael... You think I'm annoying so you find any little hole in a statement and exploit it... I highly doubt ZettBlade cares that I used his name as we had a simple 5 word discussion on it last night, and I just wanted to know from a reliable source.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  14. #1364
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    It was no bash, it was a statement that I find it inappropriate to talk names with abviously wrong assumptions to ridicule those persons, although the wrong assumption is pretty meaningless.
    As I said, I just suggest you edit your post to comment out the name. It has nothing to do with the original question, which was already answered anyway.

    EDIT-PS: And yes, I may sometimes act childish in some way too, I admit. That's most likely pretty much human nature to do every then and when, but I try not to ridicule people without a reason (I hope everyone sees enough reason for my signature though :P)- and therefore I didn't say a name with my allusion, because the person in charge should know he is being talked about.
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  15. #1365
    I'm Baaaack!
    Points: 17.067, Level: 83
    Level completed: 44%, Points required for next Level: 283
    Overall activity: 52,0%

    Registriert seit
    May 2006
    Ort
    Nowhere
    Beiträge
    2.186
    Points
    17.067
    Level
    83
    Downloads
    0
    Uploads
    0

    Standard

    Is there a 'dofile' sort of command in C? Like if I had a .txt file with this:

    Code:
    variable1 = 7
    variable2 = 4
    variable3 = 9
    How would I call these variables?

  16. #1366
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    You'd have to parse the files and set the variables yourself.

    I believe Dark_Alex's custom firmware POC had some code in it to parse a config file like this. Check it out.

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die

  17. #1367
    QJ Gamer Platinum
    Points: 57.528, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    h0000000rj
    Beiträge
    12.867
    Points
    57.528
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von homer
    That will set var3 to 123, var2 to var3(123) and var1 to var2(123).
    Nothing strange about that...
    Err?
    Wouldn't
    Code:
    int x,y,z;
    x=y=z=3
    result in z==3, y==1, x==1? IIRC, 'var=value' resolves to '1', not 'value'. Or... am I in desperate need of a C refresher here?
    [I fail @ life]

  18. #1368
    Developer
    Points: 7.058, Level: 55
    Level completed: 54%, Points required for next Level: 92
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    408
    Points
    7.058
    Level
    55
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FreePlay
    Err?
    Wouldn't
    Code:
    int x,y,z;
    x=y=z=3
    result in z==3, y==1, x==1? IIRC, 'var=value' resolves to '1', not 'value'. Or... am I in desperate need of a C refresher here?
    x, y, and z will all equal 3.

    I'm not sure I've ever seen that in Kernighan and Ritchie, but it does work that way.

    Edit: Try resolving 'x=0' and see if you get a '1' out of that. ;)

  19. #1369
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Raphael
    for(j=1;j<=num_albums;j++ ) counts from 1 to num_albums, but the albums array goes from 0 to num_albums-1
    That was it! Thank you!

  20. #1370
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von FreePlay
    Err?
    Wouldn't
    Code:
    int x,y,z;
    x=y=z=3
    result in z==3, y==1, x==1? IIRC, 'var=value' resolves to '1', not 'value'. Or... am I in desperate need of a C refresher here?
    Refresh I would say ;) == is the comparison operator resolving to 1 if var is equal to value and zero else. x=y=z=1 is best read from right to left, ie z gets set to 1, then y gets set to z (=1) and x gets set to y (=z=1).
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  21. #1371
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    As for the send-struct-via-tcp-socket I have a whole lotta questions:

    1.) How do I send a struct via a socket?

    Code:
    send(sock, (char)myStruct, sizeof(myStruct), 0);
    ?

    2.) Can I also send an array of myStructs?

    3.) If so, can I send structs that contain strings (char-arrays) of variable lenght? Like

    Code:
    typedef struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    
    artist_entry * artist_list;
    artist_list = (artist_entry *)malloc(num_artists*sizeof(artist_entry));
    
    for(i=0; i<num_artists; i++)
    {
    	[...]
    	artist_list[ i ].name = (char*)malloc(artist_name_lenght);
    	[...]
    }
    
    send(???);
    4.) If all that sending-jazz really works; How do I convert the sent string back to a struct-array?

    5.) What was the point of the universe, again?

    Thank you

    Luke

  22. #1372
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    As for the send-struct-via-tcp-socket I have a whole lotta questions:

    1.) How do I send a struct via a socket?

    Code:
    send(sock, (char)myStruct, sizeof(myStruct), 0);
    ?
    Code:
    send(sock, myStruct, sizeof(myStruct), 0);
    more likely. Typecasting a struct into a char is a bad idea generally. I'm not sure about the second parameter of the send command, but if it expects a pointer, you'd need to use &myStruct.

    2.) Can I also send an array of myStructs?
    Yes, as long as the array is one single allocation (as in objection to an array of pointers to structs).

    3.) If so, can I send structs that contain strings (char-arrays) of variable lenght? Like

    Code:
    typedef struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    
    artist_entry * artist_list;
    artist_list = (artist_entry *)malloc(num_artists*sizeof(artist_entry));
    
    for(i=0; i<num_artists; i++)
    {
    	[...]
    	artist_list[ i ].name = (char*)malloc(artist_name_lenght);
    	[...]
    }
    
    send(???);
    You can, but you will not submit the contents of the array, but only the pointer which in turn is useless on the client. So actually no, you cant. You need to make your structs non dynamic, without pointers for this to work as you want.

    4.) If all that sending-jazz really works; How do I convert the sent string back to a struct-array?
    As said in the prior post, as long as the above requirements fullfill (well, even if they don't fullfill, it would work the same way, but when you'd try to use the struct on the client, you would get a crash).

    5.) What was the point of the universe, again?
    42

    Thank you

    Luke
    No Problem :P
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  23. #1373
    QJ Gamer Platinum
    Points: 57.528, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Dec 2005
    Ort
    h0000000rj
    Beiträge
    12.867
    Points
    57.528
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    Buh. I'm going insane. Time to re-teach myself C. Sigh.
    [I fail @ life]

  24. #1374
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Raphael
    Yes, as long as the array is one single allocation (as in objection to an array of pointers to structs).
    Yes it is (using malloc).

    Zitat Zitat von Raphael
    You can, but you will not submit the contents of the array, but only the pointer which in turn is useless on the client. So actually no, you cant. You need to make your structs non dynamic, without pointers for this to work as you want.
    I was afraid that was the case. Isn't there a bad 'hacking'-way to actually copy the strings to where they are needed? Aren't there functions that allocate the memory where it's needed, to create strings in the place?
    I can't even use char name[length_of_the_longes_arti stname] in windows (can I?) so I'll probalby have cut some names. That sucks big time.

    Zitat Zitat von Raphael
    42
    oh, I forgot about that. Thanks for enlighting me
    -= Double Post =-
    Zitat Zitat von FreePlay
    Buh. I'm going insane.
    That's not neccissarily the worst thing to do, do what makes you happy...
    -= Double Post =-
    Zitat Zitat von Raphael
    You can, but you will not submit the contents of the array, but only the pointer which in turn is useless on the client. So actually no, you cant. You need to make your structs non dynamic, without pointers for this to work as you want.
    I think I'll go with my "send and parse a formatted string"-solution. Even though the memory allocation takes an ugly second.
    Geändert von Lukeson (10-17-2006 um 07:56 AM Uhr) Grund: Automerged Doublepost

  25. #1375
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    I was afraid that was the case. Isn't there a bad 'hacking'-way to actually copy the strings to where they are needed? Aren't there functions that allocate the memory where it's needed, to create strings in the place?
    I can't even use char name[length_of_the_longes_arti stname] in windows (can I?) so I'll probalby have cut some names. That sucks big time.
    Only possibility would be to make your name and albums list a fixed array of maximum size (depending on how many artists, albums per artist max you want to support) and then transfer that. It will have a big overhead though (memory and therefore transfer size), especially when a lot of artists only have 1 or 2 albums actually so the rest of the array(s) is filled with zeros.

    I think I'll go with my "send and parse a formatted string"-solution. Even though the memory allocation takes an ugly second.
    In your case that's prolly the best way to go.
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  26. #1376
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Ok, does anyone have an idea why this only goes till artist 516 of 517 and, only at the 516th artist work only 4 of 5 albums?

    Code:
    memcpy(num_artists, &artist_data, 5);
    num_artists[5]='\0';
    offset = 5;
    printf("num artists: %d\n", atoi(num_artists)); // num artists: 517
    
    
    int i,j;
    for(i=1; i<=atoi(num_artists); i++)
    {
    	memcpy(artist_name_lenght_c, &artist_data[offset], 3);
    	artist_name_lenght_c[3]='\0';
    	artist_name_lenght = atoi(artist_name_lenght_c);
    	offset += 3;
    	artist_name = (char *)realloc(artist_name, artist_name_lenght+1);
    	memcpy(artist_name, &artist_data[offset], artist_name_lenght);
    	artist_name[artist_name_lenght]='\0';
    	offset += artist_name_lenght;
    
    	memcpy(num_albums_c, &artist_data[offset], 4);
    	num_albums_c[4]='\0';
    	num_albums = atoi(num_albums_c);
    	offset += 4;
    
    	printf("artist #%d: %s (%d), %d albums:\n", i, artist_name, artist_name_lenght, num_albums);
    
    	if(num_albums==0) num_albums=1;
    	for(j=1;j<=num_albums;j++)
    	{
    		memcpy(album_name_length_c, &artist_data[offset], 3);
    		album_name_length_c[3]='\0';
    		album_name_length = atoi(album_name_length_c);
    		offset += 3;
    		album_name = (char *)realloc(album_name, album_name_length+1);
    		memcpy(album_name, &artist_data[offset], album_name_length);
    		album_name[album_name_length]='\0';
    		offset += album_name_length;
    
    		printf("     %s (%d)\n", album_name, album_name_length);
    	}
    }
    ----------------------------------------= Double Post =----------------------------------------

    I'm having more troubles:
    Errormessage: line 104: pspwamp_commands.c:104: error: invalid use of undefined type 'struct artist_entry'
    Spoiler for Whole error-list:
    pspwamp_commands.c:104: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:104: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:105: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:105: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:106: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:106: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:106: error: syntax error before ';' token
    pspwamp_commands.c:113: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:113: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:117: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:117: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:129: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:129: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:130: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:130: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:131: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:131: error: dereferencing pointer to incomplete type
    pspwamp_commands.c:134: error: invalid use of undefined type 'struct artist_entr
    y'
    pspwamp_commands.c:134: error: dereferencing pointer to incomplete type


    Code:
    pspwamp_datatypes.c
    Code:
    [...]
    typedef struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    [...]
    main.c
    Code:
    	[...]
    	artist_entry* artist_list;
    	artist_list = (artist_entry *)malloc(sizeof(artist_entry));
    	get_artists_from_server(sock, artist_list);
    	[...]
    pspwamp_commands.c
    Code:
    int get_artists_from_server(int socket, struct artist_entry * artist_list)
    {
    	[...]
    	artist_list = (artist_entry *)realloc(artist_list, atoi(num_artists)*sizeof(artist_entry));
    
    	[...]
    
    	int i,j;
    	for(i=0; i<atoi(num_artists); i++)
    	{
    		[...]
    		artist_list[i].name = (char*)malloc(artist_name_lenght+1);	//l.104
    		[...]
    	}
    }
    Does anyone have an idea?
    Geändert von Lukeson (10-17-2006 um 12:30 PM Uhr) Grund: Automerged Doublepost

  27. #1377
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Try from
    Code:
    typedef struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    to
    Code:
    typedef struct artist_entry_struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    http://www.netalive.org/codersguild/posts/1750.shtml

  28. #1378
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von head_54us
    Code:
    typedef struct artist_entry_struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    http://www.netalive.org/codersguild/posts/1750.shtml
    Hm, doesn't work, I get the same errors. Why are there actually 2 names (artist_entry_struct and artist_entry)? That kinda confuses me...

  29. #1379
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Lukeson
    Hm, doesn't work, I get the same errors. Why are there actually 2 names (artist_entry_struct and artist_entry)? That kinda confuses me...
    Which was why I left a link ;).. You have the error because the datatype artist_entry is not defined in pspwamp_commands.c. You have defined it in pspwamp_datatypes.c but pspwamp_commands.c knows nothing about this file.

    Put the artist_entry defintion in a header file with header guards and include it where you need to use that datatype.

  30. #1380
    QJ Gamer Blue
    Points: 4.511, Level: 42
    Level completed: 81%, Points required for next Level: 39
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Germany
    Beiträge
    216
    Points
    4.511
    Level
    42
    Downloads
    0
    Uploads
    0

    Standard

    Did I write pspwamp_datatypes.c up there? It's pspwamp_datatypes.h! The whole code is
    Code:
    #ifndef PSPWAMP_DATATYPES
    #define PSPWAMP_DATATYPES
    
    typedef struct artist_entry_struct {
    	char * name;
    	int num_albums;
    	char ** albums;
    } artist_entry;
    
    #endif
    and it's included in main.c and in pspwamp_commands.c


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .