#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
char** parser(char *message)
{
char a[9][256];
char* tmp =message;
bool inQuote=0;
int counter=0;
int counter2=0;
while(*tmp!='\0')
{
switch(*tmp)
{
case ',': if(!inQuote)
{
a[counter][counter2]='\0';
printf("A[%d]: %s\n",counter,a[counter]);
counter++;
counter2=0;
}
break;
case '"':
inQuote=!inQuote;
break;
default:
a[counter][counter2]=*tmp;
counter2++;
break;
}
tmp++;
}
a[counter][counter2]='\0';
printf("A[%d]: %s\n",counter,a[counter]);
return(a);
}
int main()
{
char **a = parser("N,8545,01/02/2011 09:15:01.815,\"RASTA OPTSTK 24FEB2011 1,150.00 CE\",S,8.80,250,0.00,0");
return 0;
}
The error given is at Line 38 : return from incompatible pointer type
and function returns address of local variable
EDIT Can somebody modify the code accordingly so that I can access (via pointer) the contents of 'a' from main();