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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×