473,513 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax Error

2 New Member
I've been given a nice C programme to make from my lecturer at uni. I've got to open a file then find out the average word length and frequency of each letter.

I've written it all and gotten rid of most of the errors apart from one which reads "Expression syntax in function main". I've read your guide on answering students questions, just really hoping you can point me in the right direction with what to look for. I've gone through it many times and I'm sure all the silly mistakes have gone (like missing off ; and spellings). It works fine when it asks the user for the file name of the text file and it recognises if the file is not there so I'm hoping this means that it is opening the file, however after this istead of working out the average word length etc and displaying it on the screen it gives me an 8 letter code that is constant for the file I created to test my programme on.

I've got about 18 hours before the deadline, any help would be much appreciated,

Thanks
Mar 13 '08 #1
3 1235
Laharl
849 Recognized Expert Contributor
We can't help you with errors of that nature without seeing some code.
Mar 13 '08 #2
PlainLazy
2 New Member
Ah ok, here is the part I think the error will be in...

[code] /*if the file can be found, starts counting and everything else*/
else(){

/*If the first character is a letter, then the word count error block is set to
count the character as part of a word, if not it is set to count it as not a word.*/

for(firstCharError; firstCharError==1; firstCharError++){
if(isalpha(testChar)==1){
errorBlock=1;
}
}

/*This will repeat until the end of file character is found*/
while( feof(testChar=(getc(fp)))!=1){

/*This will be used later in the word count to see if the preceeding character is a space, new line or new page*/
if(testChar==32 || testChar==10 || testChar==12){
errorCarry=2;
}
else(){
errorCarry=1;
}

switch(isalpha(testChar)) {

/*If the character is a letter then put it into capitals, count it, then increment the matching letter count array*/
case 1:
if(testChar>64 && testChar<91){
testChar=testChar+32;
}
++charCount;
testChar-=97;
++letterCount[testChar];
break;

/*If the character is not a letter, it is determined whether it is a space, new line or new page and whether
it is preceeded by a letter or punctuation using errorBlock. If so then the word count is increased*/
case 0:
if((testChar==32 || testChar==10 || testChar==12) && errorBlock==1){
++wordCount;
}
}

errorBlock=errorCarry;
}

/*After reaching the end of the document, the word count is increased if the last characters were part of a word*/
if(errorBlock==1){
++wordCount;
}

fclose(fp); [code]
Mar 13 '08 #3
Laharl
849 Recognized Expert Contributor
The compiler should tell you what line the error is in...on first glance, I don't see anything there other than an inline assignment in the while loop that might be giving you issues, since assignments have a value. To end CODE tags, you use [/code], fyi.
Mar 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3331
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
1
3221
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I...
5
4475
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
2246
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
3
16196
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
1
2213
by: Hari Sekhon | last post by:
I've written an except hook into a script as shown below which works well for the most part and catches exceptions. import sys def myexcepthook(type,value,tb): do something ...
7
1824
by: Josh | last post by:
I have a lot of except Exception, e statements in my code, which poses some problems. One of the biggest is whenever I refactor even the triviallest thing in my code. I would like python to...
7
2867
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
6
37999
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
5
4006
Banfa
by: Banfa | last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.