Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) The scanf() function could possibly be quitting at the first space it encounters. Just a second, lemme grab a guide... EDIT: scanf("%s", &variable) Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 Hmm. still the same problem. But if you type in this_is_a_sentance, it works fine, so yeah it does stop right when it encounters a space... Do i need a scanf() command for every word that i enter? Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) Well, you could setup an algorithm to replace the underscores with spaces... just a second, lemme crack open Dev-C++. EDIT: int i; int j = strlen(theString); char theFunction(char[j] variable) { for(i=0,i<=j,i++) { if (variable[i] = "_") { variable[i] = " "; } } Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted August 4, 2005 Posted August 4, 2005 The scanf() function could possibly be quitting at the first space it encounters. Just a second, lemme grab a guide... EDIT: scanf("%s", &variable) 522460[/snapback] KB is absolutely right. %s stops at white space, didn't know that s Matches a sequence of non-white-space characters; the next pointer must be a pointer to char, and the array must be large enough to accept all the sequence and the terminating NUL character. The input string stops at white space or at the maximum field width, whichever occurs first. Hmm, not quite sure then! lol... %c says you can specify a 'width', like %500c, but I just tried that and %c doesn't seem to stop accepting characters on a carriage return. .. Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) See my previous code . int i; int j = strlen(theString); char theFunction(char[j] variable) { for(i=0,i<=j,i++) { if (variable[i] = "_") { variable[i] = " "; } } Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
Blue_cow Posted August 4, 2005 Posted August 4, 2005 Am i the only one who thinks that this is all very needlessly complicated? lol. Oh well, ill learn. Thats for the head start guys! Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 4, 2005 Posted August 4, 2005 (edited) No problem. Ah crap, you'll need to use pointers I think, C dosn't support the Pass-By-Reference operator... just a tick. EDIT: Pointers... complicated... ampersands... *head explodes* Edited August 4, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted August 4, 2005 Posted August 4, 2005 Am i the only one who thinks that this is all very needlessly complicated? lol. Oh well, ill learn. Thats for the head start guys! 522475[/snapback] It is a bit. There's always gets() or fgets() If you want simple and no buffer protection gets(variable-name); should do it.. where variable name is obviously the array you want to store the string in (forgot the name of yours already lol) Otherwise, the scanf() usage would be kinda complicated. #define LENGTH 500 #define STRINGLEN(x) char blah[LENGTH]; scanf("%" STRINGLEN(LENGTH) "[^\n]", blah); printf("%s\n", blah); Share this post Link to post Share on other sites More sharing options...
Archerzz Posted August 5, 2005 Posted August 5, 2005 what language was that cause I am learning Cpp now and your not making any sense to me...???!!!!1!11!!!! Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 5, 2005 Posted August 5, 2005 (edited) That my friend is C, functions used are from the stdio.h library. EDIT: Now markie, are you going to teach me how to emulate the pass-by-reference operator? EDIT2: Well, here's the algorithm so far. I've probably messed up a few simple things, but the logic is still there. int i; int j = strlen(stringName[]); char formatter(void) { for(i=0,i<j,i++) { if(stringName[i] = "_") { stringName[i] = " " } return void; } Edited August 5, 2005 by Kamikaze_Badger Share this post Link to post Share on other sites More sharing options...
Archerzz Posted August 5, 2005 Posted August 5, 2005 so would that program be different in cpp?? Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted August 5, 2005 Posted August 5, 2005 No, you could still use the stdlib.h library in C++. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now