User Profile
Collapse
-
I don't want to seem harsh but I think you mean 'manner' (he he)... -
-
It seems that this topic probably comes up annually. I googled your question and the third entry was a thread on thescripts from last November:
http://www.thescripts.com/forum/thread212166.html...Leave a comment:
-
You just have to declare the variable "count" as an integer just as you have with the variable "i" and you must initialize to zero before you start incrementing it in your loop. Then you just reference that variable where you currently have "some code???". Also, why is your loop condition i < 300 when you have 500 numbers to check?...Leave a comment:
-
You might get a better response if you gave some feedback to the previous attempts to help you, e.g. regarding separating fields in a csv file using fgets() and strtok()
http://www.thescripts. com/forum/post2098535-4.html
The code I posted here can be easily adapted by invoking strcpy() and possibly malloc() instead of simply fprintf() with each field read in. You'll also have to maintain column and row counters to index...Leave a comment:
-
Neat. I didn't know that.
Steady on mate, I was only trying to be helpful.
Yes, I tried it, it gives error "Constant expression required in function main" with my ridiculously old fashioned compiler.
And yes, I know it won't be 12 and 21 but 1221. That was precisely what I was wondering about. I expect you couldn't read my post due to the steam coming out of your ears?
I'm...Leave a comment:
-
Unfortunately, you can't allocate str2 like that in C. You have to use malloc() to explicitly allocate memory at runtime (the compiler can't run the strlen function for you at compile time). You must then check that the allocation has worked before using the pointer.
...Code:unsigned int i, ii; int result; char str1[] = "R12R21"; char * str2 = malloc(strlen(str1)); if (str2 != NULL)
Leave a comment:
-
-
Perhaps you missed my answers to the same question which you asked yesterday.
Regarding the inappropriate use of fread() for csv files:
http://www.thescripts.com/forum/post2097892-11.html
and regarding separating fields in a csv file using fgets() and strtok()
http://www.thescripts.com/forum/post2098535-4.html...Leave a comment:
-
You read in a line at a time with fgets() and then you can use strtok() to extract each field in which you are interested.
[php]
while (!feof(i_file)) {
while (NULL != fgets(string, BUFSIZ, i_file)){
field_counter = 1;
field = strtok(string, field_delimiter s);
while (NULL != field){
switch (field_counter) {
case 1:
/* do something with 1st field */
fprintf(o_file, "%s",...Leave a comment:
-
If you are reading a text file, wherein each line can be of different length and is delimited by the newline character, then fread is inappropriate.
fread() will read a specific number of bytes and using it will unnecessarily complicate your solution. Use fgets() to read a line at a time and then use strchr() to find a comma (also look at strtok() which you may or may not find easier to use)....Leave a comment:
-
the equation you are solving is ax^2 + bx + c = 0 and you are using the formula -b +/- sqrt(b^2 - 4ac) / 2a to solve it
but wait, if a = 0 there is no ^2 term so the equation is the rather simpler linear equation bx + c = 0
if you used the quadratic equation when a = 0, and therefore also 2a = 0, you'd be dividing by 0. this is naughty!
so when a=0 use:
bx + c = 0
or
bx = 0 - c
...Leave a comment:
-
You could probably do something with a 26 element integer array whereby the first element represents the letter 'a' and is initialized with the value 2 to represent 1 press of the '2' key; the second element representing 'b' contains 22 and so on up to the 26th element representing 'z' and containing 9999.
Now if the input string to be encoded into txt contains 'dude' you take each letter in turn and subtract 'a' using the result to...Leave a comment:
-
I don't understand this at all. What does your sample input mean? Is it that there are just two people? If so then a will go to one room and b to another where they will talk to themselves. What do the space and the dash in your output represent?...Leave a comment:
-
Use strtoul() rather than atoi().
#include <stdlib.h>
unsigned long strtoul(const char *nptr, char **endptr, int base);...Leave a comment:
-
Pukur, when getc() returns EOF it is to indicate that it has read all the characters there are in the input file. It doesn't mean that it actually read a character with the value EOF from the input file and, therefore, it is not correct to write a character with the value EOF on the output file.
Also, your code is not preserving newlines.
Hope this helps...Leave a comment:
-
Or, declare an array of type integer, initialize the first two elements with the value 1 and then, looping from the third element to the final element, store the sum of the previous two elements in the current element....Leave a comment:
-
-
I tend to think of using a for loop when I know how many interations I want it to do, as when iterating over an array of a known size, and using a while loop when the number of iterations is unknown in advance, perhaps dependent on the users' choice of whether to proceed....Leave a comment:
-
Best isn't a concept you can use without context.
If you mean best in terms of getting a job then VB would probably fill this criterion better than C (but you'll get more interesting jobs using C).
C is probably the worst language to start learning programming. Pascal was specifically designed with teaching programming concepts in mind. Modula2 was its progeny introducing the nascent concept of object orientation. Java is...Leave a comment:
No activity results to display
Show More
Leave a comment: