sprintf (again)

Bjorn Sandell biorn at FKRS1.PHC.CHALMERS.SE
Wed Jun 12 19:20:08 AEST 1991


Let's se if I can be more specific :)

First a "disclaimer": I don't know much AIX and even less C.

This is a 320 machine and uname -a says AIX fkrs1 1 3 000023913100.

I'm trying to port xmail. It usally coredumps, but once I got an error
message saying something like "can't open file /tmp/tmpxxxx_" where
xxxx was a number.
After some browsing through the sorce files I (think I) found the line
where this filename should be created. It was a sprintf statement, and I've
tried to replace it with strcpy and strcat as follows:

/* if ((fp = fopen((char *)sprintf(s, "%s_", tmpName), "w")) != NULL) {*/
   strcpy(s,tmpName);
      strcat(s,"_");
       if ((fp = fopen(s, "w")) != NULL) {

Now it seems to find the /tmp/tmpxxxx_ file (no errors at least;),
but it eventually coredumps anyway.
The question is do I have to rewrite all sprintf's this way or is there an
easier way? Is there anything wrong at all with the original line?
Any and all help is welcome!

Bjorn


 ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
 3 But, but, everyone KNOWS that all the answers can be found in manuals!    3
 3 Don't you still have your copy of "Life: A User's Manual", that came with 3
 3 your wetware? :)                                                          3
 @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY



More information about the Comp.unix.aix mailing list