i can't count the times i've tried to come up with a generic string library for c that's better than doing things manually. more power to you if you can pull it off, but if you're going to write a...
Type: Posts; User: Meldreth
i can't count the times i've tried to come up with a generic string library for c that's better than doing things manually. more power to you if you can pull it off, but if you're going to write a...
the term "troll" gets thrown around way too much in the newsgroups these days. most recently the definition has changed to
i don't even bother reading newsgroups anymore unless i want to laugh at...
the ?: operator is directly related to if..else statements. convert one to the other and you know how it works.
// ((a>b)?((a>c)?a:c):((b>c)?b:c))
if (a > b)
{
if (a > c)
a;
...
that only works if isspace returns 0 or 1, and it doesn't have to because any non-zero value counts as true.
the default access level for classes is private. private members aren't visible in derived classes. change it to this and it should work without making the method completely visible to the outside...
fgets preserves any new line character. use puts if there's no new line and fputs if there is.
while(fgets(my, 200, pfile))
{
if (!strchr(my, '\n')) puts(my);
else fputs(my, stdout);...
you have to loop if you want all of the lines.
while(fgets(my, 200, pfile)) puts(my);
c doesn't let you concatenate strings with +, you need to format the strings together with sprintf or use something like strcat to do the job. i think sprintf is better for this, so here's an...
you corrupt the memory with memset. strlen looks for a '\0' character but you haven't copied anything into the memory for temp. use the same method for initializing the memory that you did for...
that's not right. int is at least 16 bits and long is at least 32 bits. on 32 bit windows both int and long are 32 bits so the guarantee is still there.
laserlight beat me to it
if i'm only going...
the only assumption i'm making is that there's always have enough room for the range of values i need. and it's not really an assumption because i guarantee it with my choice of types.
what you...
strcat modifies the first argument and a pointer to a string constant can't be modified. try this instead.
strcpy(filename, bla);
strcat(filename, txt);
double vs float: double is the default floating type. if you say 123.456 it's a double until you cast to float or suffix it with f or F. that's why i prefer double. i haven't been in a situation...
you can flush the buffer with a loop. input is line oriented and you can be pretty sure that users have to type enter at the end, so you can just search for that character.
while (getchar() !=...
your code was wrong.
then gcc is wrong, or your code is wrong. laserlight posted a program that uses tentative definitions. do you get the same error with that one?
z is just a pointer to some random place in memory. that's wrong because you can't write to memory that isn't yours and memory isn't yours unless you ask for it explicitly. you have to point that...
you're compiling as c++. c++ doesn't allow tentative definitions.
z is already a pointer. you don't need to use & on it.
strings can't be copied by assignment. you have to use a loop or strcpy.
strcpy(names[y], z);
printf("[%d]=%s\n", y, names[y]);
in your example f is a definition but q is a tentative definition. it's only a definition if there isn't another definition for q somewhere else. if there is another definition then q is a...
scanf will return 3 if all three numbers are valid. you can do this.
if (scanf("%f %f %f", &a, &b, &c) != 3)
{
fprintf(stderr, "bad input\n");
exit(EXIT_FAILURE);
}
array indexes start at 0 and end at the size of the array minus 1. your loops should be
for (a = 0; a < 2; a++)
if you're only learning c as a step to c++, c# or java, just go ahead and learn the language you want instead of some convoluted learning process. c and c++ are different enough that learning c first...
when you use a pointer, are you allocating memory to it or pointing it to an object that already exists? you have to do one of those before you can use the pointer.
i meant what i wrote. you broke it. ;)