Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a C file. 1. The program starts by printing your name with an end sign \

ID: 3529051 • Letter: T

Question

This is a C file.

1. The program starts by printing your name with an end sign ">". For example, "NAME >";

2. Then, you can type in a string. If the string is not "vi xxx", you print "I don't know this command." You keep getting a string until you get a string starting with "vi". For example, "vi myp.c". You program will then open "myp.c" for reading. If the file does not exist, then there is nothing to read.

3. Read the file into a fixed array of "mytext[1000][ 81]". Presumably, the "myp.c" text file is not too large with each line 80 characters or fewer. If there are more characters than 80 in a line, you can just ignore the characters beyond 80.

4. Close your file.

5. Change all your texts to upper case, and display the first 20 lines on your screen.

6. Then, your program will wait for a command from the keyboard.

7. If you type ":w", your program will open the same file for writing, and write your array of text into that file.

8. If you type ":q!", your program will quite.

9. If your type ":w myp1.c", your program will open "myp1.c" and write into that file. You should always close your file after finish. Remember to use function calls instead of a program of one function.

Each function should be shorter than two pages.

Explanation / Answer

please rate - thanks


I posted the other answer, try this now

works with DEV C++ perfectly


#include <stdio.h>

#include<string.h>

void getfilename(char[],char[]);

void decodefilename(char[],char[]);

int openfile(char[],FILE**);

void openfilewrite(char[],FILE**);

void inputdata(char[][81],FILE**,int*);

void convert(int,char[][81]);

void display(int,char[][81]);

void writedata(int,char[][81],FILE**);

int getcommand(char[]);

int main()

{

FILE *in;

FILE *out;


char input[21],mytext[1000][81];

char filename[21];

int lines,command;

printf("My Name>");

getfilename(filename,input);

decodefilename(input,filename);

if(openfile(filename, &in)==1) //only continue if open is successful

{inputdata(mytext,&in,&lines);

fclose(in);

convert(lines,mytext);

display(lines,mytext);

command=getcommand(filename);

if(command==0)

printf("Invalid command ");

else if(command==1)

{openfilewrite(filename,&out);

writedata(lines,mytext,&out);

fclose(out);

}

else

return 0;

}


}

void writedata(int lines,char mytext[][81],FILE** out)

{int i,j;

for(i=0;i<lines;i++)

fprintf(*out,"%s ",mytext[i]);

}

int getcommand(char filename[])

{int command;

char input[21];

printf("enter command");

fgets(input,81,stdin);

if(input[0]!=':')

return 0;

if(input[1]=='q'&&input[2]=='!')

return 2;

if(input[2]==' ')

return 1;

decodefilename(input,filename);

return 1;


}

void display(int lines,char mytext[][81])

{int last,i;

if(lines<=20) //display at most 20 lines

last=lines;

else

last=20;

for(i=0;i<last;i++)

printf("%s ",mytext[i]);

}

void convert(int lines,char mytext[][81])

{int i,j;

for(i=0;i<lines;i++)

for(j=0;j<strlen(mytext[i]);j++)

if(islower(mytext[i][j]))

mytext[i][j]=toupper(mytext[i][j]);

}

void inputdata(char mytext[][81],FILE** in,int *lines)

{int j,i;

char c;

i=0;

j=0;

c=fgetc(*in);

while(i<1000&&c!=EOF) //for each line

{

mytext[i][j]=c;

if(mytext[i][j]==' ') //done?

{mytext[i][j]=''; //last character is null;

j=0; //start next line

i++;

}

else

j++;

if(j==81) //line too long?

{while(fgetc(*in)!= ' '); //if anything left in buffer get rid of it

mytext[i][80]=''; //put null at end of string;

i++;

j=0;

}

c=fgetc(*in);

}

*lines=i;

printf("%d****%d ",i,*lines);

}

int openfile(char filename[],FILE** in)

{*in = fopen(filename,"r");

if(*in == NULL)

{ printf("Unable to open input file: %s ",filename);

return 0;

}

return 1;

}

void openfilewrite(char filename[],FILE** out)

{*out = fopen(filename,"w");

}

void decodefilename(char input[],char filename[])

{int i,j;

i=2;

while(input[i]==' ') //skip blanks

i++;

j=0;

while(input[i]!='') //do until end of filename

{filename[j]=input[i];

j++;

i++;

}

filename[--j]=''; //add null to end of filename

}

void getfilename(char filename[],char input[])

{

fgets(input,81,stdin);

while(input[0]!='v'||input[1]!='i')

{ printf("I don't know that command ");

printf("please reenter filename: ");

fgets(input,80,stdin);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote