Good evening all. I have a problem with the code I am trying to write that separates an expression into an array. I continually get a invalid page fault in Visual C++ (6). Although I didn't try it on the UNIX server, this usually indicates a segmentation fault on UNIX.
Would someone mind looking at the code below and see why I might be getting a segmentation fault?? T-I-A
Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
{
char array[100], exp[100], id[10], num[10], digit[10], letter[10];
int i=0, j=0;
printf("Please enter an expression: ");
scanf("%s", exp);
printf("%s\n", exp);
if (exp[i] == '(')
array[i] = 20;
else if(exp[i] == ')')
array[i] = 21;
else if(exp[i] == '+')
array[i] = 16;
else if(exp[i] == '-')
array[i] = 17;
else if(exp[i] == '*')
array[i] = 18;
else if(exp[i] == '/')
array[i] = 19;
else if(isdigit(exp[i]))
while(isdigit(exp[i])){
*digit = exp[i];
*num = strcat(num, digit);
++i;}
else if(isalpha(exp[i]))
while(isalpha(exp[i])){
*letter = exp[i];
*id = strcat(id, letter);
++i;}
else
printf("%c is invalid\n", exp[i]);
for(j=1; j<100; j++)
{
printf("%c\n",array[j]);
}
}