JJ.kah JJ.kah - 24 days ago 6x
C Question

scan a value in the main and pass it to a function that convert that value C language

hi friends I have that this function in C language

struct webtech tramafunction();

this function receive a value like this

/*¶bL0 L3,01,+08590323,-079343001,010215,00000000000000,-tN,000,012689997,001219456,000,7FF2,C07F,0,4,*/

and then the function make this:

struct webtech tramafunction(){
struct webtech wbt;
char buf[103]="";
printf("\n \n data destinated to convert=[%s]\n\n", buf);
int z;
printf("size of data: %d",z);
int i = 0;
char *p = strtok (buf, ",");
char *array[16]={0};
while (p != NULL)
array[i++] = p;
p = strtok (NULL, ",");

for (i = 0; i <16; ++i){
wbt.x15 = 0;
if (array[i] != NULL){

printf("data: [%s]\n", array[i]);

printf("\n \t \t --data--\n");

printf("INDEX: [%s]\n",wbt.indice);

printf("PRE INDEX: [%d]\n",wbt.prid);
return wbt;

the main do this:

int main()

struct webtech con;

con = tramafunction();
return 0;


the question is how can I make that the data to be converted(char buf[]) get read in the main and not in the function.


you just have to declare the variable

char buf[103] = ""; 

inside the function, in the header too

struct webtech tramafunction(char buf[103]);

in the main :

int main()

 struct webtech con;
 char tr[103]="";
 con = tramafunction(tr);
return 0;