Hey guys. I am currently trying to write a basic encryption/file viewing program for my linux box, and I have run into a small problem while writing it. I want to check to see if the file I am reading in has a .txt extension on it, so that the program will only take .txt files (insures someone doesn't pass some other non-ASCII file.) I have sort of isolated the problem to the code below, which no matter what I do to it, it seems to only output "Non-text file."
Can someone please tell me what I am doing wrong?Code:#include <stdio.h> #include <string.h> int main(){ char fn[100]; //String for filename char dump[100]; //Temporary extension test printf("Please enter a filename...\n> "); fgets(fn, sizeof(fn), stdin); fn[strlen(fn)-1] = '\0'; //Remove last \n strcpy(dump, fn); / dump[strlen(dump)-4] = '\0'; //Remove last four characters from dump strcat(dump,".txt"); //Make last four characters of dump .txt for extension checking. if(strcat(dump, fn) == 0){ printf("Text file."); } else{ printf("Non-text file."); } return(0); }
Thanks in advance,
Robert



LinkBack URL
About LinkBacks


