I'm new at programming. I have:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // With luck, this declares strdup()
enum { ROWS = 50 };
static char *funkc(FILE *fp,char file[50])
{
int q,row;
char charbuffer[2],ch,*map[ROWS];
ch=getc(fp);
q=1;
while (ch!=EOF){
ch=getc(fp);
q++;
}
for (row = 0; row <=q; row++){
map[row] = " ";
}
fp = fopen(file, "r");
for (row = 0; row <= q; row++) {
if (fgets(charbuffer, 2, fp))
map[row] = strdup(charbuffer);
}
for (row = 0; row <= q; row++) {
printf("%s", map[row]);
}
return map[3];
}
int main(void)
{
char *map2[ROWS];
FILE *fp;
char file[50]; // Unused variable *map[ROWS];
printf("file name \n");
scanf("%s",file); // Removed ampersand from file
if ((fp=fopen(file,"r"))==NULL)
{
printf("Error \n");
exit(1);
}
map2[0]=funkc(fp,file);
printf("%s",map2[0]); // Add missing semicolon
return 0;
}
With that I can return only single char but I need to return full char array (map[ROWS]); how can I do it?