CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Undefined Identifier EOF

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Aayush13



Joined: 12 Aug 2016
Posts: 14

View user's profile Send private message

Undefined Identifier EOF
PostPosted: Tue Aug 16, 2016 9:40 am     Reply with quote

Hey guys, I am trying to put getc() in a array and convert the string to a floating point number. So far, I have this:
Code:

void main() {
    int c;   
    int count;
    char arr[50];
    c = getchar();
    count = 0;
    while ((count < 50) && (c != EOF)) {   
        arr[count] = c;
        ++count;
        c = getchar()
    }

   for (c=0; c<count; c++) {
    putchar(c);
   }
   putchar('\n');
}

When I try to compile this program it says that EOF is an undefined identifier? I'm sure it's an easy fix but for some reason I cannot figure it out. Thanks for the help!
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Tue Aug 16, 2016 10:08 am     Reply with quote

This code comes from, or is based on something else, isn't it?

EOF normally means "End Of File", and suggests that the original code expects to deal with data stored in some sort of file system. When data comes from standard input, which in this case tends to mean from a serial port, then there if no end of file, the port is always open and the data, conceptually at least, is never ending.

With a file system, EOF would be defined by the filesystem code as a special character code that meant: there is no more data. It is there in the original code to take account of the situation where there is not enough data, i.e. less than fifty entires, to fill the array, oreventing the code from waiting forever for data that will never come.

In your code, I strongly suspect that EOF is meaningless and you should delete all references to it. On the other hand, you should also consider what should happen if there isn't enough data for some reason. Generally, with serial input, the concept of a delimiter, some character or characters that tells the code where a number ends. For example, something that reads in numbers will stop reading when it encounters anything that isn't a +/-, digit or full stop (i.e. the decimal point). A simple space is enough to end the number, as is any white space character.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

Re: Undefined Identifier EOF
PostPosted: Tue Aug 16, 2016 10:17 am     Reply with quote

Try this:

Aayush13 wrote:
Code:

#include <ctype.h>
void main() {
    int c;   
    int count;
    char arr[50];
    c = getchar();
    count = 0;
    while ((count < 50) && (isdigit(arr[count]))) {   
        arr[count] = c;
        ++count;
        c = getchar()
    }

   for (c=0; c<count; c++) {
    putchar(c);
   }
   putchar('\n');
}

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group