![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 51
| Send() not "sending" whole message Code: printf("\nPlease enter username : ");
scanf( "%s", &username);
printf("Please enter password : ");
scanf( "%s", &password);
send(sockfd, &username, strlen(&username), 0);
break;
|
| Martin_T is offline | |
| | #2 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,230
| How is "username" declared? Your use of & in all three cases here is not appropriate if these are just normal char pointers. |
| MK27 is offline | |
| | #3 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,643
| You don't need the & for scanning into an array / pointer. Also, you probably want to print your input just to be sure it's what you think it is: Code: scanf( ... ) printf( "debug: \'%s\'\n", username ); Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #4 |
| Registered User Join Date: Sep 2007
Posts: 452
| If your compiler is not complaining about strlen(&username), you've got your types wrong (or you forgot to #include <string.h>). If your compiler is complaining about strlen(&username), you should fix the problem; don't ignore warnings from a compiler, as they tend to be useful. At the very least, you should remove all those ampersands. They cannot be right (except possibly the &username in send() is acceptable, but even then you can drop it). Without seeing all of your code, though, I can't definitively say what's going wrong. It'd be really helpful to see the declarations of username and password, at least. |
| cas is offline | |
| | #5 |
| Registered User Join Date: Nov 2009
Posts: 51
| Code: char *username;
char *password;
Code: printf("\nPlease enter your new username : ");
scanf( "%s", username);
printf("Please enter your password : ");
scanf( "%s", password);
send(sockfd, username, strlen(username), 0);
break;
|
| Martin_T is offline | |
| | #6 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,643
| You didn't actually allocate space for either pointer, did you? Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #7 |
| Registered User Join Date: Nov 2009
Posts: 51
| Sorry, I am quite new to C and have not quite got to grips with the pointer stuff. Originally I had Code: char username;
char password;
Code: printf("\nPlease enter your new username : ");
scanf( "%s", &username);
printf("Please enter your password : ");
scanf( "%s", &password);
send(sockfd, &username, strlen(&username), 0);
break;
|
| Martin_T is offline | |
| | #8 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,643
| Code: char justonecharacter; char *pointertoacharacterbutnoactualallocatedmemory; char arrayofXelementsofactualallocatedspace[ X ]; Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #9 |
| Registered User Join Date: Nov 2009
Posts: 51
| Thanks! I've now declared them, for example : Code: char string[50]; |
| Martin_T is offline | |
| | #10 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,230
| No, but then you will want to restrict the amount of input in the scanf line so you cannot overflow -- scanf("%49s") or something. |
| MK27 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Desperate Over Ecs! | cookie | C Programming | 17 | 07-16-2008 01:25 PM |
| Message class ** Need help befor 12am tonight** | TransformedBG | C++ Programming | 1 | 11-29-2006 11:03 PM |
| Making a script language? | Blackroot | Game Programming | 10 | 02-16-2006 02:22 AM |
| pointers | InvariantLoop | C Programming | 13 | 02-04-2005 09:32 AM |
| Sending CChildView a Message :: MFC | kuphryn | Windows Programming | 0 | 04-06-2002 03:00 PM |