User Profile

Collapse

Profile Sidebar

Collapse
risby
risby
Last Activity: Dec 18 '06, 10:40 PM
Joined: Sep 7 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • risby
    replied to Basic Programming Question
    in C
    I don't want to seem harsh but I think you mean 'manner' (he he)...
    See more | Go to post

    Leave a comment:


  • risby
    replied to Structured Array
    in C
    You haven't asked a question....
    See more | Go to post

    Leave a comment:


  • risby
    replied to C Compiler
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to How to count numbers
    in C
    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?...
    See more | Go to post

    Leave a comment:


  • risby
    replied to reading into an array.
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to convert string to integer
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to convert string to integer
    in C
    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)
    ...
    See more | Go to post

    Leave a comment:


  • risby
    replied to Apriori algorithm in c
    in C
    Don't we all!...
    See more | Go to post

    Leave a comment:


  • risby
    replied to reading using fread
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to how to use fgets
    in C
    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",...
    See more | Go to post

    Leave a comment:


  • risby
    replied to reading a csv file
    in C
    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)....
    See more | Go to post

    Leave a comment:


  • risby
    replied to Check if variable is defined
    in C
    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
    ...
    See more | Go to post

    Leave a comment:


  • risby
    replied to Help with Program
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to help to solve this question
    in C
    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?...
    See more | Go to post

    Leave a comment:


  • risby
    replied to Reading unsigned int from command line
    in C
    Use strtoul() rather than atoi().

    #include <stdlib.h>
    unsigned long strtoul(const char *nptr, char **endptr, int base);...
    See more | Go to post

    Leave a comment:


  • risby
    replied to File convertor
    in C
    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...
    See more | Go to post

    Leave a comment:


  • risby
    replied to cprogram for fibonnacci series
    in C
    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....
    See more | Go to post

    Leave a comment:


  • risby
    replied to What hashing algorithm outputs numbers only?
    in C
    I should get some rest now, D_C. :-)...
    See more | Go to post

    Leave a comment:


  • risby
    replied to Help regarding Loops?
    in C
    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....
    See more | Go to post

    Leave a comment:


  • risby
    replied to Best Programming Language
    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...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...