C Programming: My Question: How to use C language to ask filename from user and
ID: 3586330 • Letter: C
Question
C Programming:
My Question: How to use C language to ask filename from user and put file contents in a buffer and update the count of bytes/words? (how to write getFname(..) method in C?)
typedef unsigned short u short; typedef unsigned int u int32; typedef unsigmed long u int64 uint64 getCode ( *buffer, int count) /* count = byte/word count */ egister u int64 total-0: ile (count- return XXXx; int main(...) I - ask filename from user and put file contents in a buffer and update the count of bytes/words. call getCodeOfunction to calculate code using one's complement. getFname (...) code -getcode (buffer,count) use code to validate any user-specified file'/ getFname (...) testvalidity (code, Fname)Explanation / Answer
C code:
#include <stdio.h>
int main()
{
FILE *objectFp;
char objectFilename[100];
char objectCh;
int objectLineCount,objectCharCount;
objectLineCount = 0;
objectCharCount = 0;
printf("Please enter the filename");
gets(filename);
objectFp = fopen(filename,"r");
if ( objectFp )
{
while ((objectCh=getc(objectFp)) != EOF) {
if (objectCh == ' ') { ++objectLineCount;}
if (objectCh != ' ' && objectCh != ' ') { ++objectCharCount; }
if (objectCharCount > 0) {
++objectLineCount;
++wordcount;
}
}
else
{
printf("oops..It is failed to open the file ");
}
printf("Lines of data : %d ", objectLineCount);
return(0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.