yup, that was it. thanks :)
Type: Posts; User: fazio93
yup, that was it. thanks :)
Alright, so neither feof nor ferror are being triggered (which they shouldn't because it never gets to then end of the file and an error never occurs because n=1 is a valid call of fgets. i tested it...
i understand fgets for the most part, but have a (kind of silly) conceptual question about its behavior when allocating 1 as its buffer length, like in the code below. how come when running the...
alright, exactly what i was thinking. i just wanted to make sure that wasn't another way of doing it since it didn't make much sense.
thank you MutantJohn and rcgldr.
oops, i wrote it wrong -_-. i meant int* as in int pointer, my apologies for the confusion. what i meant to say is i can change between (int*) and (int) for the first call of malloc and the program...
alright, i guess what's real confusing me then is how the following program can run successfully. i can change the first call of malloc to (row*sizeof(int)) or (row*sizeof(*int)). with the former, if...
yes, after writing it out on paper, i see how your method works.
pertaining to the second question about the int array, i see how the second method would just create one large 1d int array, so...
alright, thanks.
i have one other (somewhat unrelated) question on using malloc to create 2d arrays
to create a 2d char array (each row is a string), i would need to create an array of char...
alright, i understand now. so in other words, assignment and arrays should never be mixed at all. the correct way would be:
int main()
{
char *array = malloc(8);
strcpy(array,"hello");...
what exactly is happening? isn't "array" pointing to the address of the first byte of that 8 byte memory chunk? what does the compiler assume it is doing?
thanks
how come when declaring an array dynamically with malloc, you can use the assignment operator and string literals, but with static arrays you must use something like strcpy? does it have to do with...
Oh, alright. Because pnum < num+4 isn't attempting to reassign num. i understand.
Thank you all for clearing everything up. Much appreciated.
how does the compiler know num+4 isnt an attempt to change the array as num++ would, if num++ == num+1, or is it not the same? Or does the compiler always recognize the "a+N" format as &a[N]
wow, i feel stupid. that would be like doing ";i< i+5;i++". i was so focused on the addresses i didn't realize if was affecting both sides.
this leads me to another question though. how come "num+4"...
well, i guess that is my question. why is pnum+4 != num+4 if both are the same starting address? what does pnum+4 actually point to, if it is not pointing to the 5th element in num?
thanks
why does this print "12345"
#include<stdio.h>
int main()
{
int num[] = {1,2,3,4,5};
int *pnum = num;
never mind.
the main.c file was given by my professor for testing purposes, but i was using an older version. he had revised it using gets() instead of scanf, for this very reason.
thanks...
i have a program using an array of structures, with one of the structure's members another structure itself.
to shorten it, i removed the functions not involved with the issue, but i can post the...
thank you, once again :)
the 'i' was the problem.
as for the %s warning, i had tried that but didn't think anything of it when i saw i was still getting segfault.
i've read the that this is more...
well, i'm getting segfault again and i believe it's the same reason as before (the loop was never the problem).
even though i have -Wall in my makefle i only sometimes get a warning from the...
yep, i forgot the second part would not even be evaulated when it is an OR statement, hence the infinte loop. seems to be working now.
thanks :)
Thing is, we were given the main file as well just for testing purposes. We actually didnt even cover strings yet as thats a later chapter (which is probably why were given certain parts).
...
i want to enter a URL in as a string, and extract just the URL part.
eg:
input:
http://example.com/shop/index.php?product_id=&highlight=blue+shoes&cat_id=&sessionid=123&affid=543
output:...
ok, i understand now. thank you everyone that helped.
:)
thanks, i understand it a bit better now. i guess my question is how exactly the added "if" statement fixes the program. if the while statement was by itself (like it was) wouldn't the whole while...