Search:

Type: Posts; User: qny

Page 1 of 15 1 2 3 4

Search: Search took 0.02 seconds.

  1. The best way to deal with user input (in respect...

    The best way to deal with user input (in respect to error checking, validation, recovery) is to read full lines with fgets(), then parse those lines with sscanf().
    This requires a bit more work than...
  2. scanf() (line 29) leaves the ENTER in the input...

    scanf() (line 29) leaves the ENTER in the input buffer.
    fgets() (line 34) reads that ENTER to the first position in str.
    The subsequent test fails.

    Do not mix scanf() and fgets().

    Ignore the...
  3. Replies
    9
    Views
    1,074

    Please consider using SQLite...

    Please consider using SQLite as a replacement for flat files -- according to their own documentation SQLite was designed to replace fopen(), fread(), fwrite(), fclose(); not to replace Oracle.

    If...
  4. Thread: Strcpy function .

    by qny
    Replies
    7
    Views
    1,922

    1. Yes, it produces UB. You try to put more...

    1. Yes, it produces UB. You try to put more characters in str1 than there is space for. str1 has space for 5 characters and the zero terminator, you try to put 31 and the zero terminator in that...
  5. Thread: Database fscanf

    by qny
    Replies
    14
    Views
    1,608

    You want to have a loop where you read the data...

    You want to have a loop where you read the data from the file.
    basically:

    /* pseudo code */
    fopen();
    some_kind_of_loop {
    /* readdata */
    /* printdata */
    }
    fclose();
  6. Thread: Database fscanf

    by qny
    Replies
    14
    Views
    1,608

    Where is pFile referenced in your program? ???...

    Where is pFile referenced in your program? ???
    Let's see:

    line 5: ok, declare the variable
    line 8: ok (kinda -- you missed testing for errors), open the file for reading
    line 9: ok (kinda --...
  7. Replies
    1
    Views
    1,301

    Why do you remove 1 from num_employees in line...

    Why do you remove 1 from num_employees in line 12?
    Without that, the for loop executes one less time than required (and the array size is too short).
  8. Thread: joining codes

    by qny
    Replies
    5
    Views
    1,432

    Please, please, please ... learn to use arrays! ...

    Please, please, please ... learn to use arrays!


    #include <stdio.h>

    int main(void) {
    int input, i;
    const char *station[] = {
    "Ashford Station", "Brentworth Station",...
  9. Replies
    17
    Views
    1,751

    If the user types " ...

    If the user types "<SPACE> <4> <2> <SPACE> <ENTER>" this will not consume the <ENTER>.
  10. syntax error on line 12 ... if you meant that...

    syntax error on line 12 ...

    if you meant that to be a for and are ussing a C89 compiler: no return from main.

    Also the cast to the return value of malloc is redundant. You don't check for...
  11. Replies
    2
    Views
    1,287

    If you don't need tight control, try atoi()...

    If you don't need tight control, try atoi().
    If you want tighter control of errors, prefer strtol().

    Read the function descriptions!!!


    char input1[] = "-c123";
    char input2[] = "-c 123";...
  12. Unlike "proper string functions" they also work...

    Unlike "proper string functions" they also work with non null-terminated char arrays.


    char a[12] = "not a string";
    char b[18] = "another non-string";
    char c[] =...
  13. Replies
    17
    Views
    1,751

    No, getchar()...

    No, getchar() reads a single character. What you can do with getchar(), is manage the input little by little and build larger parts as you go along. Remember to properly terminate the strings!

    ...
  14. Despite their names, strncpy() and strncat() were...

    Despite their names, strncpy() and strncat() were not designed to be used with strings.
    I suggest you do not use them.

    Also your string delimiters are not part of the Basic character set and are...
  15. Replies
    17
    Views
    1,751

    I did offer a suggestion with an edit. Maybe you...

    I did offer a suggestion with an edit. Maybe you didn't see it.

    Do not mix scanf() and other input functions.
    Best way (the one with most control) is to read lines with fgets() and then deal with...
  16. Replies
    17
    Views
    1,751

    Please explain line 17. row+= (row-1); Why...

    Please explain line 17.

    row+= (row-1);

    Why do you want to change the value held by `rows`?
    What do you want to achieve with it?

    EDIT: Never mind the above

    Don't mix scanf() and other...
  17. Replies
    7
    Views
    1,485

    It could print 7 6 8 it could print yellow it...

    It could print 7 6 8
    it could print yellow
    it could format your hard drive
    it could send money from your bank account to mine

    Don't write Undefined Behaviour!

    To see what your compiler, with...
  18. Replies
    7
    Views
    1,485

    The order in which the program executes the...

    The order in which the program executes the parameters to a function is unspecified.

    Relying on a specific order is Undefined Behaviour.

    Don't rely on specific order.
    Don't write code with...
  19. Replies
    6
    Views
    1,545

    Unix-like OSes treat text mode files and binary...

    Unix-like OSes treat text mode files and binary mode files the exact same way.
    Using binary mode when not dealing with text is, nevertheless, a good idea TM no matter the OS in use.
  20. Replies
    6
    Views
    1,545

    Instead of looking at the file with a text...

    Instead of looking at the file with a text editor, try a hex editor.
  21. Replies
    2
    Views
    617

    With a different indentation (more like what the...

    With a different indentation (more like what the program does) your program looks like this:


    int main ()
    {

    int days, pennies;

    {
    printf ("days of month: ");
  22. Replies
    13
    Views
    2,812

    you already have your own defined function

    Just rename main() ...



    int my_defined_function(){
    /* YOUR EXACT CODE AS ABOVE */
    }

    and add a different main that calls your function
  23. Replies
    12
    Views
    14,460

    Basically change the vector/linked list before...

    Basically change the vector/linked list before you call the recursive function and change it back afterwards.
    When the recursive function reaches the base case, just print the result (or save it in...
  24. Replies
    12
    Views
    14,460

    Use recursion ... The sets of 5 numbers (1 to...

    Use recursion ...

    The sets of 5 numbers (1 to 9) that add up to 28 include:
    : the number 1 plus the sets of 4 numbers (2 to 9) that add up to 27
    : the number 2 plus the sets of 4 numbers (3 to...
  25. You need to initialize wklyWage (to 0).

    You need to initialize wklyWage (to 0).
Results 1 to 25 of 358
Page 1 of 15 1 2 3 4