Old Nick
Advanced Member level 1
scanf read string with whitespace
Hi
I'm writing some data aquisition code in which the folder and files that the data are stored in are user definable without changing the code. Now I've managed to do this, but I'm having a problem with 'white space' (space bar especially) in the user inputed names. I'm using scanf() to read in a user inputed string which treats white space in a manner that causes problems with my program. If it was just me that was goint to use the code then it wouldn't be a problem.
Anyway
pprintf("enter directory ->");
scanf("%s", &input2);
sprintf(dirname,"c://%s",input2);
mkdir(dirname);
printf("enter filename base ->");
scanf("%s", &input);
these are some of the pertinent parts of the code. Anywhite space in the names causes code malfunction, Is there another way of reading in a string, or is there a way of ignoring/blocking white-space entry?
Cheers,
Nick
Hi
I'm writing some data aquisition code in which the folder and files that the data are stored in are user definable without changing the code. Now I've managed to do this, but I'm having a problem with 'white space' (space bar especially) in the user inputed names. I'm using scanf() to read in a user inputed string which treats white space in a manner that causes problems with my program. If it was just me that was goint to use the code then it wouldn't be a problem.
Anyway
pprintf("enter directory ->");
scanf("%s", &input2);
sprintf(dirname,"c://%s",input2);
mkdir(dirname);
printf("enter filename base ->");
scanf("%s", &input);
these are some of the pertinent parts of the code. Anywhite space in the names causes code malfunction, Is there another way of reading in a string, or is there a way of ignoring/blocking white-space entry?
Cheers,
Nick