I wrote this code it is surposed to take an input string like
a"bcd"e"fgh"i
and extract the strings that occur inside the " " and tsore them in an array once the whole input string has been examined the function dumpstring should print out all the extracted strings but instead it just prints the last extracted string.
so if the input above was used the output would be
string1
fgh
string2
fgh
but it should be
string1
bcd
string2
fgh
any help would be appreciated
a"bcd"e"fgh"i
and extract the strings that occur inside the " " and tsore them in an array once the whole input string has been examined the function dumpstring should print out all the extracted strings but instead it just prints the last extracted string.
so if the input above was used the output would be
string1
fgh
string2
fgh
but it should be
string1
bcd
string2
fgh
any help would be appreciated
Code:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int numberStrings = 0;
char in[256];
char extract[100];
char stored[100][256];
char key = '"';
char quote[2];
char *p1, *p2;
getString()
{
int p = 0, record = 0, i = 0, j = 0, c = 0;
while (in[p] != NULL)
{
if (strcmp(key, in[p]) == 0)
{
if (record == 0)
{
record = 1;
p++;
}else
{
record = 0;
extract[i] = NULL;
i = 0;
while (extract[c] != NULL)
{
stored[j][c] = extract[c];
c++;
}
stored[j][c] = NULL;
c++;
numberStrings++;
j++;
c = 0;
}
}
if (record == 1)
{
extract[i] = in[p];
i++;
}
p++;
}
}
dumpString()
{
int a, b = 0, d = 0, count = 0;
for (a = 0; a < numberStrings; a++)
{
printf("\nString %u\n", count);
printf("\n%s", stored[b]);
b++;
count++;
}
}
main()
{
printf("\nPlease enter the data to be examined: ");
scanf("%s", in);
getString();
dumpString();
exit(0);
}