Jump to content
Sign in to follow this  
Blue_cow

Looking To Learn Something

Recommended Posts

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites

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

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites
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

See my previous code :D.

 

int i;
int j = strlen(theString);

char theFunction(char[j] variable) {

for(i=0,i<=j,i++) {
   
   if (variable[i] = "_") {
       variable[i] = " ";
       
   }
}

Edited by Kamikaze_Badger

Share this post


Link to post
Share on other sites

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

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites
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

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

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 by Kamikaze_Badger

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...