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

File I/O: Strings 1. Create string str initialized to alphabet 2. Create a FILE

ID: 3822442 • Letter: F

Question

File I/O: Strings

1. Create string str initialized to alphabet

2. Create a FILE pointer MyTxt

3. Open file “message.txt” for text write

4. Write string to file

5. Close the file

6. Open file for text read

7. Read string from file

8. Rewind to start of file

9. Read 5 characters from file

10. Position to letter 'j' in file

11. Read 5 characters starting at 'j' in file

Illustration 4:

41)In Illustration 4-1 What statement would create a string called str initialized to lower case alphabet?

A) char str[] = "abcdefghijklmnopqrstuvwxyz";

B) char str[] = {"abcdefghijklmnopqrstuvwxyz"};

C) char* str[] = "abcdefghijklmnopqrstuvwxyz";

D) char str[] = [abcdefghijklmnopqrstuvwxyz];

42)In Illustration 4-2 What statement would create a file pointer MyTxt?

A) MyTxt FILE*;

B) FILE MyTxt;

C) FILE* MyTxt;

D) MyTxt* FILE;

43)In Illustration 4-3 What statement would open the file “message.txt” to write text with MyTxt?

A) MyTxt = fopen("message.txt", "wb");

B) MyTxt = fopen("message.txt", "w");

C) MyTxt = fopen("w", "message.txt");

D) MyTxt = fopen("message.txt");

44)In Illustration 4-4 What statement would put str into “message.txt” file?

A) fputs(MyTxt);

B) fwrite(str, MyTxt);

C) fputs(MyTxt, str);

D) fputs(str, MyTxt);

45)In Illustration 4-4 What alternative statement would put str into “message.txt” file?

A) fprintf(str);

B) fprintf(MyTxt,str);

C) fprintf(MyTxt,”%s”);

D) fprintf(MyTxt,”%s”,str);

46)In Illustration 4-5What statement would close “message.txt” file?

A) fclose (MyTxt);

B) fclose(str);

C) FileClose(“message.txt”);

D) FILE(close, MyTxt);

47)In Illustration 4-6 What statement would open the file “message.txt” to read text with MyTxt?

A) MyTxt = fopen("message.txt");

B) MyTxt = fopen("message.txt", "rb");

C) MyTxt = fopen("message.txt", "r");

D) MyTxt = fopen( "r", "message.txt");

48)In Illustration 4-7What statement would read int buf[80]; from “message.txt” file?

A) fgets(buf, 80, MyTxt);

B) finput(buf, 80, MyTxt);

C) fgets(buf, MyTxt);

D) finput(80, MyTxt);

49)In Illustration 4-7 If the alphabet from “message.txt” file is read into buf, how many characters will be read?

A) 26 letters

B) 27 (26 letters + '')

C) 28 (26 letters + '')

D) 80

50)In Illustration 4-8 How can “message.txt” file rewind to the beginning?

A) rewind(“message.txt”);

B) rewind(MyTxt);

C) rewind(start);

D) rewind(80, MyTxt);

51)In Illustration 4-9 How can only 5 characters be read from “message.txt” file after rewind?

A) fgets(buf);

B) fgets(buf, 5, MyTxt);

C) fgets(buf, 6, MyTxt);

D) fgets(MyTxt, 5);

52)In Illustration 4-10 How can the file pointer be positioned just before the letter j in “message.txt” file?

A) fseek(fp, 9, SEEK_CUR);

B) fseek(fp, 9, SEEK_SET);

C) fseek(fp, 9, SEEK_END);

D) fseek(fp, 9);

53)In Illustration 4-10 How can 5 letters including the letter j be read from “message.txt” file after positioning the file pointer just before the letter j?

A) fgets(buf);

B) fgets(buf, 5, MyTxt);

C) fgets(buf, 6, MyTxt);

D) fgets(MyTxt, 5);

Explanation / Answer

41)In Illustration 4-1 What statement would create a string called str initialized to lower case alphabet?

A) char str[] = "abcdefghijklmnopqrstuvwxyz";

B) char str[] = {"abcdefghijklmnopqrstuvwxyz"};

C) char* str[] = "abcdefghijklmnopqrstuvwxyz";

D) char str[] = [abcdefghijklmnopqrstuvwxyz];

42)In Illustration 4-2 What statement would create a file pointer MyTxt?

A) MyTxt FILE*;

B) FILE MyTxt;

C) FILE* MyTxt;

D) MyTxt* FILE;

43)In Illustration 4-3 What statement would open the file “message.txt” to write text with MyTxt?

A) MyTxt = fopen("message.txt", "wb");

B) MyTxt = fopen("message.txt", "w");

C) MyTxt = fopen("w", "message.txt");

D) MyTxt = fopen("message.txt");

44)In Illustration 4-4 What statement would put str into “message.txt” file?

A) fputs(MyTxt);

B) fwrite(str, MyTxt);

C) fputs(MyTxt, str);

D) fputs(str, MyTxt);

45)In Illustration 4-4 What alternative statement would put str into “message.txt” file?

A) fprintf(str);

B) fprintf(MyTxt,str);

C) fprintf(MyTxt,”%s”);

D) fprintf(MyTxt,”%s”,str);

46)In Illustration 4-5What statement would close “message.txt” file?

A) fclose (MyTxt);

B) fclose(str);

C) FileClose(“message.txt”);

D) FILE(close, MyTxt);

47)In Illustration 4-6 What statement would open the file “message.txt” to read text with MyTxt?

A) MyTxt = fopen("message.txt");

B) MyTxt = fopen("message.txt", "rb");

C) MyTxt = fopen("message.txt", "r");

D) MyTxt = fopen( "r", "message.txt");

48)In Illustration 4-7What statement would read int buf[80]; from “message.txt” file?

A) fgets(buf, 80, MyTxt);

B) finput(buf, 80, MyTxt);

C) fgets(buf, MyTxt);

D) finput(80, MyTxt);

49)In Illustration 4-7 If the alphabet from “message.txt” file is read into buf, how many characters will be read?

A) 26 letters

B) 27 (26 letters + '')

C) 28 (26 letters + '')

D) 80

50)In Illustration 4-8 How can “message.txt” file rewind to the beginning?

A) rewind(“message.txt”);

B) rewind(MyTxt);

C) rewind(start);

D) rewind(80, MyTxt);

51)In Illustration 4-9 How can only 5 characters be read from “message.txt” file after rewind?

A) fgets(buf);

B) fgets(buf, 5, MyTxt);

C) fgets(buf, 6, MyTxt);

D) fgets(MyTxt, 5);

52)In Illustration 4-10 How can the file pointer be positioned just before the letter j in “message.txt” file?

A) fseek(fp, 9, SEEK_CUR);

B) fseek(fp, 9, SEEK_SET);

C) fseek(fp, 9, SEEK_END);

D) fseek(fp, 9);

53)In Illustration 4-10 How can 5 letters including the letter j be read from “message.txt” file after positioning the file pointer just before the letter j?

A) fgets(buf);

B) fgets(buf, 5, MyTxt);

C) fgets(buf, 6, MyTxt);

D) fgets(MyTxt, 5);

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