nul terminating a int array
Posted
by robUK
on Stack Overflow
See other posts from Stack Overflow
or by robUK
Published on 2010-06-08T15:52:28Z
Indexed on
2010/06/08
16:02 UTC
Read the original article
Hit count: 326
c
Hello,
gcc 4.4.4 c89
I was just experimenting with a int array. And something just came to my mind. Can I nul terminate it. For example, I am using a 0 to nul terminate. However, 0 could well be a valid value in this array.
The code below will terminate after the 5. Even though I mean 0 to be a valid number. However, I could specify the size of the array. But in this case, I don't want to this as I am just interested in this particular problem.
Many thanks for any advice,
#include <stdio.h>
static void test(int *p);
int main(void)
{
int arr[] = {30, 450, 14, 5, 0, 10, '\0'};
test(arr);
return 0;
}
static void test(int *p)
{
while(*p) {
printf("Array values [ %d ]\n", *p++);
}
}
© Stack Overflow or respective owner