473,480 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

stray"\26" in program

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

Jul 3 '07 #1
11 7737
On Jul 3, 10:02 am, Grzesiek <grzesiek.wilanow...@gmail.comwrote:
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, it is advised to prefer <ctsdioinstead of <stdio.h>
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

Jul 3 '07 #2
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


On 3 Lip, 07:16, Neelesh Bodas <neelesh.bo...@gmail.comwrote:
On Jul 3, 10:02 am, Grzesiek <grzesiek.wilanow...@gmail.comwrote:
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, it is advised to prefer <ctsdioinstead of <stdio.h>
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

Jul 3 '07 #3
Grzesiek wrote:
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.
Jul 3 '07 #4
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

Jul 3 '07 #5
Grzesiek wrote:
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.
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.
--
Alan Johnson
Jul 3 '07 #6
On Jul 3, 12:09 pm, Alan Johnson <a...@yahoo.comwrote:
Grzesiek wrote:
Hi Red Floyd
Why aren't you allowed to modify source? Then copy hello.cpp to
myhello.cpp and edit that
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
Jul 3 '07 #7
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 :-)

Jul 3 '07 #8
Grzesiek <gr*****************@gmail.comwrites:
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--
Jul 3 '07 #9
On Jul 3, 10:41 am, Grzesiek <grzesiek.wilanow...@gmail.comwrote:
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
let tedious jobs to machines : write a program to remove the character
from all of them.

regards,
FM.

Jul 3 '07 #10
On Jul 3, 7:42 am, Grzesiek <grzesiek.wilanow...@gmail.comwrote:
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
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

Jul 3 '07 #11
On 3 Lip, 14:34, James Kanze <james.ka...@gmail.comwrote:
On Jul 3, 7:42 am, Grzesiek <grzesiek.wilanow...@gmail.comwrote:
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.)

--
James Kanze (GABI Software) email:james.ka...@gmail.com
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

Jul 4 '07 #12

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

Similar topics

11
457
by: Grzesiek | last post by:
Hi I have Main.cpp and Hello.cpp files in my Dev C++ project. Main.cpp #include "Hello.cpp"
0
7048
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,...
1
6743
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
6966
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
5344
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,...
1
4787
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2999
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...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
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.