> Hi I am programming in Xcode 2.3 a C application running Max OS X
> 10.4.7. I cannot determine why the program wont compile when I add
[quoted text clipped - 5 lines]
> char *temp =channel1[channelLocation]+"\t"+channel2[channelLocation]
> +"\t"+channel3[channelLocation]+"\t"+channel4[channelLocation];
The compiler is complaining because it's a C compiler, and that's not C code.
C doesn't use + to concatenate strings. That's precisely what the quoted error
message is saying, that you're passing invalid operands (i.e. strings) to a
binary operator (+) that can't handle them.
> writeToFile(temp);
> printf("%d\t\t\t\t%d\t\t\t\t%d\t\t\t\t%d\n",
> channel1[channelLocation], channel2[channelLocation],
> channel3[channelLocation], channel4[channelLocation]);
If %d works to print these values, then they're not strings. They're ints.
So the above situation gets even worse - in addition to (mis)using + for
concatenation, you're also trying to concatenate strings with ints.
What you want is asprintf(), which is more or less the same as printf(),
except that it allocates a large-enough char* buffer and returns it, instead
of simply printing the results. Example:
char *temp;
asprintf(&temp, "%d\t%d\t%d\t%d\n", channel1[channelLocation],
channel2[channelLocation],
channel3[channelLocation],
channel4[channelLocation]
);
if (NULL != temp) {
// Buffer was allocated successfully
writeToFile(temp);
// You're responsible for free()ing temp when you're done with it
free(temp);
}
sherm--

Signature
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Ivan - 18 Dec 2006 23:43 GMT
It works!!! Thanks Sherm. I dont think I would have figured that out
on my own. Thanks again and for the fast response.