I'm doing a OS class.

Trying to implement this pseudo code:

* Forking is fun! ­ Simple tips
First, fork the child process:

pid_t ForkPID;
ForkPID = fork();
Then write a quick switch statement!

switch (ForkPID) {
// ­-1, fork failure
case ­-1:
printf("Error: Failed to fork.\n"); break;
// 0, this is the child process
case 0:
break;
// > 0, parent process and the PID is the child's PID
default:
}
I get an error:

ForkEnc.cc:18: error: stray ‘\302’ in program
ForkEnc.cc:18: error: stray ‘\255’ in program

line 18 is:

case -­1:

can someone help me out.

I may be wrong but what I feel is the pid_t data type within switch() is causing the error with -1. As negativity of the choice element is not correctly defined in some cases its better if you use an integer variable to hold the ForkPid value.

as
int pid;
.
.
pid=fork();
.
.
switch(pid)
{
.
.
}

This will satisfy your needs as the returned value of pid from a child process shall always come within the limits of signed integers.

didn't fix the error...

The same code compiled for me.
Platform HP-UX

Which is yours?

Hi,
I googled and found this... Hope it is not an offence to place links to other forums for information...

http://ubuntuforums.org/showthread.php?t=381626

Check that it might help you... The actual issue is there are some invisible characters... Good Luck...

i copied a code online from some MS power point slide. the ' in text files and in Microsoft applications are different. makes sense ever tried to write an email in word and copy it onto a gmail back in the day. you use to get weird character at '.

thanks ahamed101!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.