Hello today i wanted to know like how many strings inside a str * but problem its 1 + orginal strings and I wanted to make this following code so the str get rand strings only after like 2nd string only but i keep getting weird results as if the thing counted the strings as 7 not 6
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
char *Names[]= {
"first",//stops
"second",//vowels
"third",
"fourth","fifth","sixth","seventh"
};
int main(void)
{
int y;
srand(time(NULL));
y= 2+ rand() % sizeof (Names) / sizeof(Names[0]);
printf("%d\n",y);
puts(Names[y]);
getchar();
return 0;
}
try print
y= sizeof (Names) / sizeof(Names[0]);
and it will print 7th character not 6th i know its 7 but arrays start from zero so i dunno how to fix this .....
and i dunt wanna make it so i have some tests if to test if y==7 --y because that would be lame :P