I am trying to make a program that will later one test myself by asking me standard idoms(this is not a assignment this is me practicing for my midterm).
I am trying to make a check to compare my user input answer compared to the correct standard idom
I am currently working on a standard idom to "procces an array"
size_t i;
for(i = 0; i < n; i++)
I am currently working on a regular expresion on the for loop part this is what I have.
if(sscanf(line2, "%[^([a-z][]=[][0-9];[][a-z][]<[][a-z];[][a-z++])",holdLoop)==1)
but this does not seem to work. Also if anyone has a site with C sscanf regular expresion that would be very helpful(since I got alot of standard idoms to write with different expresions.
Here is my whole code.
[code]
Code:
#include <stdio.h>
#include <string.h>
void idiom1(char idiomOne[]);
int main()
{
char prompt[] = "Please Enter In the correct idiom";
char idomOne[] = "Standard idom to process an array";
idiom1(idomOne);
return 0;
}
void idiom1(char idiomOne[])
{
char varType[1024];
char line[1024];
char compare[] = "size_t i;";
char forLoop[] = "for(i = 0; i < n; i++)";
char holdLoop[1024];
char line2[1024];
char prompt[] = "Enter the loop part now: ";
int i;
while(1)
{
printf("%s: ", idiomOne);
if(fgets(line, 1024, stdin) == 0)
{
clearerr(stdin);
break;
}
for (i = 0; line[i] != '\0'; i++)
{
if (line[i] == '\n')
{
line[i] = '\0';
}
}
if(sscanf(line, "%[^[][a-z];", varType) == 1)
{
if(!strcmp(varType, compare))
{
printf("This is correct:");
printf("%s",prompt);
if(fgets(line2,1024,stdin) == 0)
{
clearerr(stdin);
break;
}
if(sscanf(line2, "%[^([a-z][]=[][0-9];[][a-z][]<[][a-z];[][a-z++])",holdLoop)==1)
{
fprintf(stderr,"does this work");
if(!strcmp(holdLoop,forLoop))
{
printf("correct for line2");
}
else
{
printf("NOT correct for line2");
}
}
}
else
{
printf("NOT What VarType Held %s \n", varType);
}
}
}
}