+ 1
Write a C program to print the type of file where filename is accepted through Command Line.
I need to use 'fileStat' method. How can I get the desired output ? #include<stdio.h> #include<stdlib.h> #include<fcntl.h> #include<unistd.h> #include<sys/stat.h> #include<sys/types.h> #include<dirent.h> int main (int argc, char *argv[]) { struct stat fileStat; char fnm[30]; int fd=0; FILE *filename; printf("Enter file name= "); scanf("%s",fnm); if ( ( fd = open (fnm , O_RDONLY) ) == -1){ perror ( "open " ); system("pause"); exit (1) ; } if(fstat(fd, &fileStat)<0) return 1; printf("Information for %s\n",fnm); __________// expected filetype syntax here system("pause"); return 0; } _________________________________ => Input: Enter file = abc.txt => Output: file type= .txt
1 Réponse
+ 2
I guess this will help you
https://code.sololearn.com/c13uYX9irT5P/?ref=app