stray"\26" in program

G

Grzesiek

Hi

I have Main.cpp and Hello.cpp files in my Dev C++ project.

Main.cpp

#include "Hello.cpp"

int main(){
return 0;
}

Hello.cpp

#include<stdio.h>

int main(){
printf("Hello World!");
getchar();
return 0;
}
 //this rises error

My question is: Suppose i cant modify Hello.cpp. What can i do to make
the compiler to ignore the square at the end of Hello.cpp file?

Regrads

Grzesiek Wilanowski
 
N

Neelesh Bodas

Hi

I have Main.cpp and Hello.cpp files in my Dev C++ project.

Main.cpp

#include "Hello.cpp"

Including a source file in another source file is a *very* bad idea.
int main(){
return 0;

Strictly speaking, return 0 is not necessary.
}

Hello.cpp

#include<stdio.h>

In a C++ File said:
int main(){

You will end up with *two* definitions of "main". Compiler will not
accept this.
printf("Hello World!");
getchar();
return 0;}

//this rises error

What error does this rise?
My question is: Suppose i cant modify Hello.cpp. What can i do to make
the compiler to ignore the square at the end of Hello.cpp file?

What square?
Regrads

Grzesiek Wilanowski

-Neelesh
 
G

Grzesiek

Thanks Neelesh, but its not the case here.

I will put it that way. Here is a Hello.cpp file

#include<stdio.h>

int main(){
printf("Hello World!");
getchar();
return 0;
}
x // this rises error

Suppose i cant modify Hello.cpp file, that means i cant remove stray
x.
Then i want to include Hello.cpp file into any other file, lets call
it Test.cpp. What code should i add to Test.cpp to make the compiler
to ignore stray x in Hello.cpp file?

This is a problem i came across trying to use Genetic Algorithms
Library
http://lancet.mit.edu/ga/
in my Dev C++ project

In GA library evry file has a char ''(instead of x in the sample
program above) at the end of it and that rises "stray \26 in program"
error.

Grzesiek
 
R

red floyd

Grzesiek said:
Thanks Neelesh, but its not the case here.

I will put it that way. Here is a Hello.cpp file

#include<stdio.h>

int main(){
printf("Hello World!");
getchar();
return 0;
}
x // this rises error

Suppose i cant modify Hello.cpp file, that means i cant remove stray
x.
Then i want to include Hello.cpp file into any other file, lets call
it Test.cpp. What code should i add to Test.cpp to make the compiler
to ignore stray x in Hello.cpp file?

This is a problem i came across trying to use Genetic Algorithms
Library
http://lancet.mit.edu/ga/
in my Dev C++ project

In GA library evry file has a char ''(instead of x in the sample
program above) at the end of it and that rises "stray \26 in program"
e

Why aren't you allowed to modify source? Then copy hello.cpp to
myhello.cpp and edit that.
 
G

Grzesiek

Hi Red Floyd
Why aren't you allowed to modify source? Then copy hello.cpp to
myhello.cpp and edit that

Of course, I can modify hello.cpp but i dont want to do it. I want to
solve the problem without modifying hello.cpp. I think conditional
compilation (#if)is needed in here but i dont know how to tell the
compiler to ignore the char.

I dont want to modify hello.cpp because in GA library there are
hundreds of files with square char at the end. Its hard to modify all
of them, isnt it?

Grzesiek
 
A

Alan Johnson

Grzesiek said:
Hi Red Floyd

Of course, I can modify hello.cpp but i dont want to do it. I want to
solve the problem without modifying hello.cpp. I think conditional
compilation (#if)is needed in here but i dont know how to tell the
compiler to ignore the char.

Try something like this before the include. Replace x with whatever the
unprintable character is.

#define x

That is, just make the preprocessor replace that erroneous token with
nothing.
I dont want to modify hello.cpp because in GA library there are
hundreds of files with square char at the end. Its hard to modify all
of them, isnt it?

Being a programmer, this shouldn't really be THAT much of a challenge.
:) Especially if you are on a Unix derived system and can use
bash/grep/sed.
 
N

Neelesh Bodas

Try something like this before the include. Replace x with whatever the
unprintable character is.

#define x

That is, just make the preprocessor replace that erroneous token with
nothing.
I doubt if that works. Whether C++ allows any non-printable character
as an identifier after #define depends on what the character is and
also on the implementation. The language doesnot require that every
non-printable character be a valid identifier.

Of course, if you are lucky, it may work, but, that would surely be
more of a "very specific" workaround than a solution.

-Neelesh
 
G

Grzesiek

Neelesh is right
I doubt if that works. Whether C++ allows any non-printable character
as an identifier after #define depends on what the character is and
also on the implementation. The language doesnot require that every
non-printable character be a valid identifier.

The non-printable char (printed as a square in Dev C++) is just EOF
(0x26). Its not allowed to write

#define *square*

I see that i have to modify hello.cpp file in the end :)
 
S

Sherm Pendley

Grzesiek said:
I see that i have to modify hello.cpp file in the end :)

How hard can that be? Any decent text editor should be able to do a multi-
file search & replace in seconds, even for hundreds of files.

sherm--
 
T

terminator

Hi Red Floyd


Of course, I can modify hello.cpp but i dont want to do it. I want to
solve the problem without modifying hello.cpp. I think conditional
compilation (#if)is needed in here but i dont know how to tell the
compiler to ignore the char.

I dont want to modify hello.cpp because in GA library there are
hundreds of files with square char at the end. Its hard to modify all
of them, isnt it?

Grzesiek

let tedious jobs to machines : write a program to remove the character
from all of them.

regards,
FM.
 
J

James Kanze

Suppose i cant modify Hello.cpp file, that means i cant remove stray
x.
Then i want to include Hello.cpp file into any other file, lets call
it Test.cpp. What code should i add to Test.cpp to make the compiler
to ignore stray x in Hello.cpp file?

Let me see if I've got this right. You have files which don't
contain legal C++, you want to include them in a C++ program,
and you want the compiler to ignore the errors. That doesn't
sound reasonable to me.
This is a problem i came across trying to use Genetic Algorithms
Libraryhttp://lancet.mit.edu/ga/
in my Dev C++ project
In GA library evry file has a char ' '(instead of x in the sample
program above) at the end of it and that rises "stray \26 in program"
error.

Sounds like an error occured in copying the files somewhere. If
you're 100% sure that the only copy error is that one extra
character was appended, the obvious solution is to edit the
files to remove it. A three line script with any decent command
interpreter. Maybe even less. On my system, something like:

for x in ` find . -name '*.cpp' `
do tr -d '\026' $x > /tmp/xxx && mv /tmp/xxx $x
done

The syntax will obviously be different for other systems, but
something along those lines should certainly be possible.

Note that if you're using vim, you can also do it in
interactive, with ":argdo s/^Z//g" command.

(I'm just wondering: did you tar the files from a Windows
machine to Unix, using binary instead of ascii. '\26' is the
Windows EOF character, and it is not abnormal for a text file to
contain it as the last character in the file on disk. Reading
in text mode under Windows, however, you won't see it.)
 
G

Grzesiek

Let me see if I've got this right. You have files which don't
contain legal C++, you want to include them in a C++ program,
and you want the compiler to ignore the errors. That doesn't
sound reasonable to me.


Sounds like an error occured in copying the files somewhere. If
you're 100% sure that the only copy error is that one extra
character was appended, the obvious solution is to edit the
files to remove it. A three line script with any decent command
interpreter. Maybe even less. On my system, something like:

for x in ` find . -name '*.cpp' `
do tr -d '\026' $x > /tmp/xxx && mv /tmp/xxx $x
done

The syntax will obviously be different for other systems, but
something along those lines should certainly be possible.

Note that if you're using vim, you can also do it in
interactive, with ":argdo s/^Z//g" command.

(I'm just wondering: did you tar the files from a Windows
machine to Unix, using binary instead of ascii. '\26' is the
Windows EOF character, and it is not abnormal for a text file to
contain it as the last character in the file on disk. Reading
in text mode under Windows, however, you won't see it.)

--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Thanks to evryone , especially for James Kanze for deep understanding
of my problem. Finally i used freeware replaceEm
http://www.orbit.org/replace/
to get rid of the non-printing squares:)

Grzesiek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top