473,545 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StrongARM processor EOF different?

Hello,

I have compiled the following for Linux Intel and Windows, and the
loop breaks correctly at EOF, but the same code for the StrongARM
processor does not break correctly (keeps going until max number is
reached). What gives? What am I doing wrong? I tried both getc and
fgetc, same result.

The code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ... main begins... */
char c;
// loop until done or until we have 50000
while(wordnumbe r < 49999)
{
c = getc(file);

if(c == EOF)
{
break;
}
else
{
/* code keeps going */

Help will be greatly appreciated!

Kirst
Nov 14 '05 #1
5 1205
Jobs'R'Us wrote:
/* ... main begins... */
char c; ^^^^
getc() returns an int.
// loop until done or until we have 50000
while(wordnumbe r < 49999)
{
c = getc(file);

if(c == EOF)


Are you *sure* that EOF is a char?
Nov 14 '05 #2


Jobs'R'Us wrote:
Hello,

I have compiled the following for Linux Intel and Windows, and the
loop breaks correctly at EOF, but the same code for the StrongARM
processor does not break correctly (keeps going until max number is
reached). What gives? What am I doing wrong? I tried both getc and
fgetc, same result.

The code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ... main begins... */
char c;
// loop until done or until we have 50000
while(wordnumbe r < 49999)
{
c = getc(file);

if(c == EOF)
{
break;
}
else
{
/* code keeps going */


Function fgetc(file) returns type int. The macro EOF expands to
type int. So c should be type int, not char.

What type is wordnumber? If it is type int you should be aware
that 49999 may exceed the maximum value of an int. If the type is
unsigned int or a larger integral type, then you are safe.

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3
On 16 Aug 2004 17:58:16 -0700, ki************* **@hotmail.com
(Jobs'R'Us) wrote in comp.lang.c:
Hello,

I have compiled the following for Linux Intel and Windows, and the
loop breaks correctly at EOF, but the same code for the StrongARM
processor does not break correctly (keeps going until max number is
reached). What gives? What am I doing wrong? I tried both getc and
fgetc, same result.

The code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ... main begins... */
char c;
// loop until done or until we have 50000
while(wordnumbe r < 49999)
{
c = getc(file);

if(c == EOF)
{
break;
}
else
{
/* code keeps going */

Help will be greatly appreciated!

Kirst


As others have said, getc() returns an int, and for EOF it returns an
int value less than 0 and not equal to any valid char value.

And on all the ARM implementations I know of, ''plain'' char is
unsigned, not signed.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
ki************* **@hotmail.com (Jobs'R'Us) writes:
I have compiled the following for Linux Intel and Windows, and the
loop breaks correctly at EOF, but the same code for the StrongARM
processor does not break correctly (keeps going until max number is
reached). What gives? What am I doing wrong? I tried both getc and
fgetc, same result.

The code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ... main begins... */
char c;
// loop until done or until we have 50000
while(wordnumbe r < 49999)
{
c = getc(file);

if(c == EOF)
{
break;
}
else
{
/* code keeps going */


This is question 12.1 in the C FAQ. (Google "C FAQ" to find it.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
Thanks guys, you're the greatest!

Kirst
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4106
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:my-javascript-ext="my-ext1" extension-element-prefixes="my-javascript-ext"
3
3110
by: Amit Dedhia | last post by:
Hi I am developing a Dot net application (involving image processing) on a uni processor. It works well on my machine. I then take all my code on a multi processor, build and run the application there. There is performance degradation. The usual performance of the application on MP machine is better than that of uni processor machine....
2
1691
by: Gernot Frisch | last post by:
Hi, I saw that the PocketHAL library has a faster memcpy for large blocks on an StrongARM processor. Can anyone give me the source for such a memcpy? -- -Gernot int main(int argc, char** argv) {printf ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
3
1429
by: Michel Meex | last post by:
Hello, I have an application, that has been running on a single processor server for more then a year without any problems. Now I'm migrating to a dual processor server, and I'm experiencing problems with threading. The application is actually a kind of job schedular. For all jobs, I can set a recurring interval (daily,weekly, monthly...
11
2300
by: sunil | last post by:
Dear All, I have created a .Net service in 2.0 and running it on a machine that has a Quad Processor. It is failing with the following error. "Error 1053: The service did not respond to the start or control request in a timely fashion" This is what I saw in event Viewer. Timeout (30000 milliseconds) waiting for the MyService Server service...
5
6577
by: nano2k | last post by:
Hi I need to protect my application in a way. Just a "soft" protection, not a very strong one. So, using WMI I get the processor ID and compare it against a key. Protection works well, until someone (me) decides to clone the system. After cloning, all cloned systems work with the same key. That is, WMI returns the same processor id on all...
168
7110
by: broeisi | last post by:
Hello, Is there a way in C to get information at runtime if a processor is 32 or 64 bit? Cheers, Broeisi
10
1821
by: ajaygargnsit | last post by:
Let's say we are using the gcc compiler, and a Pentium 4. Also say there is another machine running same gcc compiler, but a different processor, say Sunsparc. So, now, even though only the processor differs, yet different machine codes will be generated for the same code. (I assume it to be the case, kindly correct me I am wrong..) Now how...
1
1209
by: Hansen | last post by:
Hi, I'm writting an application for a StrongArm target, that is able to run on a win32 simulator. I'm need to write to the serial port and would like to use open(), ioctl() and so on without having to use ifdef's for win32 (and then use _open() etc.) I'm looking for some sort of wrapper that wraps the win32 api with the matching POSIX...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7442
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7776
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4965
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
729
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.