Reputation: 205
I am kind of new to c , but i cant figure out how to send this string to the function. I tried several things but it tells me it is expecting something
program.c: In function ‘main’:
program.c:48:87: error: expected identifier or ‘(’ before ‘long’
char string1[] =
"This is process %d with ID %ld and parent id %ld\n", i, (long)getpid(), (long)getppid());
write(wrfd1,string1, strlen(string1));
Is there a better way to do this? Thank you
Upvotes: 0
Views: 76
Reputation: 11
The first problem is:
(long)getppid())
the bracket number doesn't match.
Another one is that you cannot assign a string like this:
int a = 100;
char str[] = "A is %d", a;
You should use 'sprintf' to do this, as mentioned above.
Upvotes: 1
Reputation: 163228
I think you meant to use sprintf
:
int length = 100;
char string1[length];
if(sprintf(string1, "This is process %d with ID %ld and parent id %ld\n", i, (long)getpid(), (long)getppid())) {
write(wrfd1,string1, length);
}
Upvotes: 3