Not sure what you mean? Do you mean how to calculate the average? Then the answer is to add up all numbers and devide it by the number of numbers. F.ex.: The average og 4,5,6 = (4+5+6)/3.
Other...
Type: Posts; User: cnewbie1
Not sure what you mean? Do you mean how to calculate the average? Then the answer is to add up all numbers and devide it by the number of numbers. F.ex.: The average og 4,5,6 = (4+5+6)/3.
Other...
Elysia: That was going to be my follow-up question. I know that it's possible, but I wondered if it would be a more "tidy" way of doing it. In the example I was playing with, where the values needs...
Thanks - good answer :-)
One of the reasons I allmost never get any real work done, I think, is that I allmost allways stumble over small things that I don't understand. And then, instead of pragmatically solving it another...
Would this be a valid way of doing it, then?
int main (int argc, char *argv[]) {
char buf[25];
if (!func(buf)) {
printf("Oh crap, that didn't work!\n\n");
return 0;
}
Of course. Impresise wording on my part.
However, I still don't see the point of using the extra pointer when you can just pass buff[] to the function. As per the examples above like this:
...
Hm, ok. I think I understand. You could f.ex. return the pointer to an array, and in the calling code use that to check wether or not the function did it's job; if the returned pointer is null, then...
Ok, about what I thought. But is there a reason for using f.ex. a *char function which returns nothing, or could it just as well be a void function?
I read a (seemingly good) tutorial on how to "return arrays from functions". This is one of the methods described: "Have the caller allocate an array and use that within the function":
char...
Logical, of course.
So how can I get the size of an array created by using malloc()?
1:
char parray[10];
strcpy(parray, "abcdefghij");
printf("%s, %lu\n", parray, sizeof(parray)/sizeof(char));
2:
char *marray = malloc(10*sizeof(char));
strcpy (marray, "abcdefghij");...
Ah, of course. Should've read the specification more closely. Frightningly simple. Thanks.
I'm running this string through strtok():
00:name:2:morename:2204a3741a4f4c636acb71cca5da1b0041446e554d9fb1a2dceec29428491a17
- calling function - reads the above line from a text file and...
Yah, of course you're right. And I've looked at strtok. The problems remain, however, as strtok just gets the substrings. I can do that manually as well. But:
1. How to resize a char array of size...
Fordi: Thanks, but C != C++
ssharinsh: Hmm....exactly what does that do?
I'm doing this (quite simple) operation:
- Read a line from a semi-colon-separate file:
00:name:22:name2:blablablablablahblahblah
This string has a length of 104, allowing for the these...
ssharish2005: You're getting and error using the code I pasted? Exactly what are you doing?
I thought so too. Also, why should it be necessary to return anything from that function? The array is created in the calling function, and the populate() function populates the array using the...
Ah, thanks - think I got it now:
char *populate (char (*)[64]);
int main (int argc, char *argv[]) {
char str[5][64];
populate(str);
puts(str[0]);
The strcpy name is only because I forgot to change the name from the previous example I worked on. The thing I'm trying to find out is how to do the same as this with a 2-d array:
char...
Hm...do I need to redefine the my_strcpy() function? If I remove everything inside the function:
char *my_strcpy (char *);
int main (int argc, char *argv[]) {
char str[5][64];
...
I know I should read more, and I am, but sometimes it helps to get clear example answers to my more or less clear example questions. So, here goes:
This works:
char *my_strcpy (char *);
...
I know that indexes start at zero, of course.
Ah, dagn - I get it.
int table[2][3] = { {0,0,0},{1,1,1} };
000 is row one, 111 is row two, of course.
Thanks :-)
Definition of two-dimensional array:
data_type array_name[row_size][column_size];
This:
int table[2][3] = { {0,0,0},{1,1,1} };
works. Why? This should mean a size 2 row and a size 3...