Please answer all the questions and show all work using C-programming. Create a
ID: 3825671 • Letter: P
Question
Please answer all the questions and show all work using C-programming.
Create a script that will Read SNL_CAST.TXT file and change the name Michael to Mike and save the result. (Let's save the change on SNL_CAST_2.txt) Create a script that will find the Z-value from the "Distribution.txt" Create a script with array of structures to store Sailor Warrior's Name and their GPA. You need to type the name and GPA, then the script need to create a txt file based on the name and GPA Score Usagi Tsukino 1.98 Rei Hino 3.2 Amy Mizuno 4.0 Makoto Kino 2.9 Minako Aino 2.21 Haruka Tenou 3.5 Michiru Kaiou 3.78. Do not ask how l remember all the names!) Create a script that will read a specified text file "Waroftheworlds.txt" and count the number of the word mars.Explanation / Answer
Problem1
Program(C):-
#include <stdio.h>
#include<string.h>
int main()
{
char in_name[80],out_name[80];
FILE *in_file,*out_file;
char word[50];
printf("Enter file name: ");
scanf("%s", in_name);
in_file = fopen(in_name, "r");
if (in_file == NULL)
printf("Can't open %s for reading. ", in_name);
else
{
printf("Enter file name: ");
scanf("%s", out_name);
out_file = fopen(out_name, "w");
if (in_file == NULL)
printf("Can't open %s for reading. ", in_name);
else
{
while (fscanf(in_file, "%s", word) != EOF)
{
if(strcmp(word,"Michael")==0)
{
fprintf(out_file,"%s","Mike");
fprintf(out_file," ");
}
else
{
fprintf(out_file,"%s",word);
fprintf(out_file," ");
}
}
fclose(in_file);
fclose(out_file);
}
}
return 0;
}
Output:-
Enter file name:
names.txt
Enter file name:
names2.txt
names.txt(file)
Aaron
Abdiel
Jonson
Michael
Abel
Abraham
Abram
Adam
Adan
Addison
Aden
Aditya
Adolfo
Adonis
Adrian
Adriel
Jacob
Michael
names2.txt(file)
Aaron
Abdiel
Jonson
Mike
Abel
Abraham
Abram
Adam
Adan
Addison
Aden
Aditya
Adolfo
Adonis
Adrian
Adriel
Jacob
Mike
Problem4
Program(c):-
#include <stdio.h>
#include<string.h>
int main()
{
char in_name[80],out_name[80];
FILE *in_file,*out_file;
char word[50];
int count=0;
printf("Enter file name: ");
scanf("%s", in_name);
in_file = fopen(in_name, "r");
if (in_file == NULL)
printf("Can't open %s for reading. ", in_name);
else
{
while (fscanf(in_file, "%s", word) != EOF)
{
if(strcmp(word,"Mars")==0)
{
count++;
}
}
fclose(in_file);
}
printf("The number of Mars words in file = %d ",count);
return 0;
}
OUTPUT:-
Enter file name:
names.txt
The number of Mars words in file = 4
names.txt(file)
Mars
Aaron
Abdiel
Jonson
Michael
Abel
Abraham
Abram
Adam
Mars
Adan
Addison
Aden
Aditya
Adolfo
Adonis
Adrian
Mars
Adriel
Jacob
Michael
Mars