Hi,
The below is my situation,
Input String : abc 123$ abc 123$ abc123$abcabcabc 123$
From the above string i want to store the starting index of "123$" code and the "123$" string.
When i debugged and found, for first iteration(codecount=0) i'm able to store both index and string but for the second time(when codecount =1) its crashing. Can anyone suggest me to proceed further???
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct _MyStruct
{
char Mycode[10];
int Index;
};
void MyFun(char *String, _MyStruct *MyStruct[] )
{
char *TempString;
int i=0,j=0, code = 0, codecount = 0;
while(String[i])
{
if((String[i] == L'1') && (String[i+1] == L'2'))
{
//store the starting index of 123$ code
MyStruct[codecount]->Index =i; //its crashing when it go for second time (say codecount=1)
while(String[i] != L'$')
{
//storing 123 code
MyStruct[codecount]->Mycode[code++] = String[i];
i++;
}
MyStruct[codecount]->Mycode[code++] = String[i];//add $ with 123
i++;
codecount++; // increment the count of 123 code
}
i++; j++;
}
}
int main()
{
char *a = "abc 123$ abc 123$ abc123$abcabcabc 123$";
_MyStruct *MyStruct;
MyStruct = (_MyStruct*)calloc(1,sizeof(struct _MyStruct));//Allocating MyStruct
printf("String with 123 code: %s", a);
MyFun(a,&MyStruct);
printf("\123 code is: %s",MyStruct[0].Mycode); //here i'm trying to print 123 first occurence
return 0;
}