In my C code I am given the following string as input:
"c:\tc\bin\a c j k.jpg"
I tried to read the input with scanf but it failed (passing the input both with and without quotation marks) and I am looking for an other solution.
My code is as follows:
char keytext[16],zzz,source[100],dest[100];
short int a;
size_t readcount;
clrscr();
printf("input the key text(max 16 characters):");
scanf("%s",&keytext);
printf("input file name:");
scanf("%s",&source);
/*fgets(source,100,stdin);
namelen=strlen(source);
if(source[namelen-1]=='\n')
source[namelen-1]='\0';*/
printf("output file name:");
scanf("%s",&dest);
The format specifier
%swill stop consuming input when the first whitespace character is encountered, so it will only read until the end ofC:\tc\bin\a. To read up to thek.jpgyou can use a scanset:The format specifier
"%127[^\n]"means read up to the next newline character but no more than 127 characters to prevent buffer overrun. You should check the return value ofscanf()before using its output, it returns the number of assignments made.