I'm new to C and encountered a weird problem. Here's the code:
Code:
int main(){
char name[]="";
readname(name) ;
printf("The filename is: %s\n",name);
printf(name);
printf("snazzyjazz.txt\n"); //error checking
if (strcmp(name,"snazzyjazz.txt")>0) {
printf("less");
} else {
puts("more");
} //error checking
FILE * my_stream;
my_stream = fopen (name,"r+");
Code:
void readname (char names[])
{
printf("Please enter the filename\n");
fgets(names,30,stdin);
printf("names = %s",names);
}
I compile this with no problem, but gives "File could not be opened". the strcmp tells me name and "snazzyjazz.txt" are not equal. but when I print them I get the same output. Rather confused.