CODE:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define fname "a.f"
main()
{
FILE *fp;
int x,len=0;
char str[100],file[20];
printf("Enter file name: ");
gets(file);
if (file == fname)
{
fp=fopen(fname,"w");
printf("file opened!\n\n");
printf("\nEnter the sentence to count:\n");
scanf("%s",&str);
len=strlen(str);
printf("lenght: %d",len);
for (x=0;x<=len;x++)
{
fputc(str[x], fp);
}
fclose(fp);
printf("\nString Entered: %s",str);
printf("File Was Successfully Created!");
}
else
{
printf("Invalid filename!");
}
getchar();
getchar();
}
ok , so i want the user to input the filename and if he/she enters it "a.f" it will create the file else it will exit program.
my problem is that it doesnt see if statement but runs else statement when i enter filename.
wat am i doing wrong!