I am new to programming and have faced this particular problem:
int *FindLine(char *lines[100],int line_number) {
char **pointer=lines;
int i,*stack,counter=0;
stack=(int*)calloc(30,sizeof(int));
for (i=0;i<line_number;i++)
if (*pointer[i]=='{') {
stack[counter]=i+1;
counter++;
}
return stack;
}
main(){
char *line[100];
FILE *fp;
char FileName[20];
char Buffer[100];
fp=fopen(FileName,"r");
while(fgets(Buffer,100,fp)!=NULL) {
line[i]=strdup(Buffer);
i++;
}
NumOfLines=i;
Stack=FindLine(line,NumOfLines);
system("PAUSE");
}
stack is supposed to have stored the number of the line each '{' appears in , instead it only stores it if '{' is the first char on the line. is there a way on C to access every single individual character of the strings pointed by the pointers in the array of pointers to strings ?
mallocinstead ofcalloc. Did not calloc allocate memory on the stack (function scope memory)? Hence one cannot return it outside.callocdoes not allocate memory from the stack. It allocates it the from the heap.