+ 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

13th Mar 2021, 7:06 AM
Shravani Pandit
Shravani Pandit - avatar
2 Respuestas
16th Mar 2021, 9:09 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar