Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with strcpy, gcc4-0, mac OsX?

Status
Not open for further replies.

julie25

Programmer
Aug 7, 2003
22
FR
Hi,

I am developing in C on mac OsX.

I recently downloaded the new version of gcc (gcc4-0) and I have a problem of execution on the following code.

It seams that the use of strcpy have action on the memory and modify the value in the lieu variable (variable of the loop)

I tried on other computers with other versions of gcc and it functions well.
Does anyone know about such a problem?

Thank you very much for your help

Julie



Code:
for (lieu=0 ; lieu<nb_lieu ; lieu++)
  {
    printf("\n lieu %d \n",lieu); // print 0, 1, 2, 3...	OK
    convert_lieu(lieu,chlieu); // this function does not affect lieu, 
                                          // just put in chlieu the adequate value
    printf("\n lieu %d \n",lieu); // print 0, 1, 2, 3...	OK

    /****** HERE ******/
    strcpy(ch, "\n Blablabla ");
    printf(" %d \n",lieu); // print enormous values
    /************/
    strcat(ch,chlieu);

   }
 
How is your variable ch defined?
Maybe it is too short to hold the string "\n Blablabla " ?
(And some compilers are more forgiving than others.)
 
That's it!

Thank you very much for your help Hoinz

Julie

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top