I'm a college student learning how to program in C. We recently got an assignment to transpose a list of names. We have to read in from a file a list of names and print them out and write to a file with the names going downwards.
I'm not asking for anyone to do my homework so please don't tell me that you won't because I know that. I simply need some pointers.
I'm going to use a 2 dimensional array as well as a double for loop for the printing.
Does anyone have any pointers on how to do this?
Code:
- #include <string.h>
- #include <stdio.h>
-
- char transpose_text(char names[20][60])
- {
- int i, j;
- for (i=0;i<17;i++)
- for(j=0;j<60;j++)
- printf("%s", names[i][j]);
-
-
- }
-
- void main (void)
- {
- FILE *pnames, *trans;
- char names[20][60];
- int i; /* first for loop variable */
- int j; /* second for loop variable */
-
- pnames = fopen(file directory, "r");
- trans = fopen(file directory, "w");
-
- while (fscanf (pnames, "%d", &trans) != EOF)
- {
- fgets(names, 60, pnames);
- printf("%s", names);
- fprintf(trans, "%s \n", names);
- }
-
- transpose_text(names[20][60]);
-
- getche();
- }
I currently have this but it doesn't transpose the names yet. I'm working on that. Any help?