So I have to scan text from a file into an array, but I am only allowed to use scanf() to achieve this. In the file, there are 22 lines and the longest line is 455 characters long. When I compile, I get various warnings. I have been trying to find a solution but nothings seems to help my list of warnings and errors.
#include <stdio.h>
#include <stdlib.h>
#define NUM_ROWS 22
#define LENGTH_OF_LONGEST_LINE 455
void textInit(char array[]);
int main(void) {
char patty [NUM_ROWS][LENGTH_OF_LONGEST_LINE];
textInit(patty[NUM_ROWS][LENGTH_OF_LONGEST_LINE]);
return 0;
}
void textInit(char array[]) {
int x = 0;
for (x = 0; x < 22; ++x) {
scanf("%455s", array[x]);
}
return;
}
The errors I recieve are:
StPat.c: In function âmainâ:
StPat.c:14:4: warning: passing argument 1 of âtextInitâ makes pointer from
integer without a cast [enabled by default]
textInit(patty[NUM_ROWS][LENGTH_OF_LONGEST_LINE]);
^
StPat.c:9:6: note: expected âchar *â but argument is of type âcharâ
void textInit(char array[]);
^
StPat.c: In function âtextInitâ:
StPat.c:26:7: warning: format â%sâ expects argument of type âchar *â, but
argument 2 has type âintâ [-Wformat=]
scanf("%455s", array[x]);