1. What C statement is used to open a file? 2. Write a single line of code (assu
ID: 3625939 • Letter: 1
Question
1. What C statement is used to open a file?2. Write a single line of code (assume that all other needed code is present) that will create a FILE pointer named myfile.
3. Write a single line of code (assume that all other needed code is present) that will use the FILE pointer myfile to open the file c: extfile.txt for input (read) operations.
4. Why is it important that we test the file pointer after the fopen to verify that the file opened properly?
5. What reasonable action(s) might you take if a file did NOT open properly?
6. We use scanf to input numeric data from the keyboard, what statement would you use to input numeric data from a text file?
7. What C statement is used to close a file?
8. What is an array?
9. How many data types does C permit in a single array?
10. Write a single line of code (assume that all other needed code is present) that will create a ten element integer array called myintarray.
11. What is the index value of the first position in your array myintarray?
12. What is the index value of the last position in your array myintarray?
13. Write the code (use a for loop) to initialize each of the ten elements of myintarray to the value 5.
14. What is a structure?
15. Does C syntax allow us to create an array of structures?
16. Does C syntax allow us to have an array as one of the structure elements?
17. Write the code needed to declare a structure with two integer elements. (All you are doing is declaring the structure, assume all other needed code is present.)
18. Write a single line of code that will create the variable mystruct that is a structure of the type you created above. Do NOT initialize the structure elements.
19. Write a line of code for each element in mystruct (created above) that will initialize the element. Initialize the first element to 5 and the second element to 10. (You will need two lines of code. Assume that all other needed code is present.)
20. Give an example of a standard C function.
21. Why might you create a user function for your C program?
22. What is the purpose of a function prototype?
23. Write a single line of code for a function prototype (assume that all other needed code is present). The user function should be named myaddfunction, return an integer value, and accept two integers as input parameters.
24. Write the code to define (create) the user function myaddfunction. myaddfunction accepts two integers (int1 and int2), adds them together and stores in sum in a local variable named sum. The function then returns the value of sum. (You are only defining (writing the code for) the function. Assume that all other needed code is present.)
Explanation / Answer
please rate - thanks
message me if you have any questions
1. What C statement is used to open a file? fopen
2. Write a single line of code (assume that all other needed code is present) that will create a FILE pointer named myfile. FILE *myfile;
3. Write a single line of code (assume that all other needed code is present) that will use the FILE pointer myfile to open the file c: extfile.txt for input (read) operations. myfile = fopen("c:\textfile.txt","r");
4. Why is it important that we test the file pointer after the fopen to verify that the file opened properly?otherwise you will not get the correct data
5. What reasonable action(s) might you take if a file did NOT open properly? send an error message stating such, and asking to check that the file really does exit
6. We use scanf to input numeric data from the keyboard, what statement would you use to input numeric data from a text file? fscanf
7. What C statement is used to close a file? fclose
8. What is an array? multiple adjacent locations in memory of the same type, that are referenced by name and index
9. How many data types does C permit in a single array? one
10. Write a single line of code (assume that all other needed code is present) that will create a ten element integer array called myintarray. int myintarray[10];
11. What is the index value of the first position in your array myintarray? 0
12. What is the index value of the last position in your array myintarray? 9
13. Write the code (use a for loop) to initialize each of the ten elements of myintarray to the value 5.
int i;
for(i=0;i<10;i++)
myintarray[i]=5;
14. What is a structure? a group of memory locations, referenced by the same name, where the elements can have different data types
15. Does C syntax allow us to create an array of structures? yes
16. Does C syntax allow us to have an array as one of the structure elements? yes
17. Write the code needed to declare a structure with two integer elements. (All you are doing is declaring the structure, assume all other needed code is present.)
struct sample
{
int first;
int second;
};
18. Write a single line of code that will create the variable mystruct that is a structure of the type you created above. Do NOT initialize the structure elements. struct sample mystruct;
19. Write a line of code for each element in mystruct (created above) that will initialize the element. Initialize the first element to 5 and the second element to 10. (You will need two lines of code. Assume that all other needed code is present.)
mystruct.first=5;
mystruct.second=10;
20. Give an example of a standard C function. sqrt to find the square root of a number
21. Why might you create a user function for your C program? when you are going to repeatly do the same thing more then one. example to sort an array
22. What is the purpose of a function prototype? define to the compiler that the function exists and is user defined
23. Write a single line of code for a function prototype (assume that all other needed code is present). The user function should be named myaddfunction, return an integer value, and accept two integers as input parameters. int myaddfunction(int,int);
24. Write the code to define (create) the user function myaddfunction. myaddfunction accepts two integers (int1 and int2), adds them together and stores in sum in a local variable named sum. The function then returns the value of sum. (You are only defining (writing the code for) the function. Assume that all other needed code is present.)
int myaddfunction(int a,int b)
{int sum=a+b;
return sum;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.