View Single Post
Old Nov 17th, 2005, 10:10 PM   #1
Blighttdm
Newbie
 
Blighttdm's Avatar
 
Join Date: Oct 2005
Posts: 17
Rep Power: 0 Blighttdm is on a distinguished road
String error in if statement

The Problem:
As I try to compile a small C program I get the following error messages:
ghp11.c:25: error: syntax error before '{' token
ghp11.c: At top level:
ghp11.c:30: error: syntax error before '(' token
ghp11.c:30: error: `len' undeclared here (not in a function)
ghp11.c:30: error: syntax error before '==' token
ghp11.c:33: warning: data definition has no type or storage class
ghp11.c:34: error: syntax error before '}' token
ghp11.c:33: error: storage size of `input' isn't known
These errors occur in the second

Code:

 if(input[len]=='y')
 {
  input[len]='i';
  input[len+1]='e';
  input[len+2]='s';
 }

elseif(input[len]=='s')
 {
  input[len+1]='e';
  input[len+2]='s';
 }

elseif(((input[len-1]=='c')&&(input[len]=='h'))) //line 30
 {
  input[len+1]='e';
  input[len+2]='s';
 }                                               //line 34

elseif((input[len-1]=='s')&&(input[len]=='h'))
 {
  input[len+1]='e';
  input[len+2]='s';
 }

Now I know a couple of reasons it may not work but I'm not sure and my manual gives me little advice. Could it be:
-Len can't be altered like that because it was a result of strlen?
-I din't initialize a variable properly?
-Some string syntax?
-General syntax that I missed?
-I missed some big idea and messed up big time?

As always thank you for your help,
Blight
Blighttdm is offline   Reply With Quote