Jump to content

Looking To Learn Something


Blue_cow

Recommended Posts

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...