Search:

Type: Posts; User: lemnisca

Page 1 of 3 1 2 3

Search: Search took 0.01 seconds.

  1. Thread: Memory Map

    by lemnisca
    Replies
    3
    Views
    3,374

    For the course on C I did last year, we had to...

    For the course on C I did last year, we had to draw 'memory diagrams'. Not sure if that's the same thing, but it meant basically drawing rectangles representing memory locations for each variable and...
  2. Replies
    15
    Views
    2,147

    Also, you have "If" with a capital 'I'. It needs...

    Also, you have "If" with a capital 'I'. It needs to be lowercase "if".
  3. Replies
    9
    Views
    1,444

    Your for loop goes through every integer up to...

    Your for loop goes through every integer up to half the number you are testing to see if it is a factor. If it is, then the number cannot be prime. Note that it is actually only necessary to go up to...
  4. And you should always check the return value of...

    And you should always check the return value of malloc, like so:

    if((p = malloc(sizeof(int) * size)) == NULL)
    exit(1);
    /* And print a useful error message if you want */
    In practice,...
  5. Replies
    3
    Views
    952

    If it's a function you're writing, you can write...

    If it's a function you're writing, you can write it to accept a variable number of arguments and use function pointers as fgw_three said, but I don't think it's possible if it's some arbitrary...
  6. Replies
    15
    Views
    2,147

    On the line after your while, you have an opening...

    On the line after your while, you have an opening brace with no matching closing brace. This is probably what's causing your compiler to complain. The code would be much clearer to you, and you would...
  7. Replies
    15
    Views
    2,007

    oh, indeed...that's just me not checking the code...

    oh, indeed...that's just me not checking the code I post carefully enough. It should, of course, be fmt[10] = '\0';. This is why I always turn on plenty of warnings when I compile...:)
  8. Replies
    15
    Views
    2,007

    The other thing you can do with printf is...

    The other thing you can do with printf is generate your format string beforehand to include however many spaces, backspaces etc. you like. You can use sprintf, strncat and so on inside loops to build...
  9. Replies
    2
    Views
    1,122

    I think how you lay it out is pretty much up to...

    I think how you lay it out is pretty much up to you, but it's a good idea to make it logical, readable, and consistent. So have things that relate to each other be close together, use good...
  10. Thread: do while loop

    by lemnisca
    Replies
    3
    Views
    925

    You can get one character of input using...

    You can get one character of input using getchar(). Suppose you do:

    int c;
    c = getchar();
    you can then simply do:

    if(c == 'y)
    /* do something */
    else if(c == 'n')
    /* do something...
  11. Replies
    4
    Views
    4,238

    main() is where the program starts. Without main,...

    main() is where the program starts. Without main, how would it know where to begin? Would it just pick a random function and hope for the best? main() defines a starting point.

    The thing reporting...
  12. Replies
    7
    Views
    1,665

    Did you try moving it to the start of main? If...

    Did you try moving it to the start of main? If you remove the printf it would then be at the start, this is probably why it works when you do that. Also it will work when it's outside of main because...
  13. Replies
    7
    Views
    1,665

    Try putting the struct declaration at the start...

    Try putting the struct declaration at the start of main, instead of after the printf statement.

    When I compiled this code with gcc, I got:

    $ gcc -Wall -pedantic -ansi tarotcard.c -o tarotcard...
  14. I'm studying electrical engineering and also have...

    I'm studying electrical engineering and also have a C course as part of my degree requirements, nearly finished the C course now, only the exam to go. Not sure what you're asking here though. I would...
  15. Replies
    3
    Views
    5,898

    Wouldn't it be easier to do what, for instance, ...

    Wouldn't it be easier to do what, for instance, Matlab does and simply store the polynomials as an array? The length of the array is the degree of the polynomial plus one, and each element of the...
  16. Firstly, note that ~ isn't the only thing that...

    Firstly, note that ~ isn't the only thing that bash expands - in fact, bash does a great deal of mucking around with the user input before the command actually gets executed. If you want to do all...
  17. Replies
    16
    Views
    3,285

    cat foo.c | sed s/float/long long/g :P long...

    cat foo.c | sed s/float/long long/g
    :P

    long or long long will most likely be precise enough for you, but if you're not satisfied with that, then I suppose you'll have to use a library (or write...
  18. Thread: Lost in C

    by lemnisca
    Replies
    8
    Views
    2,421

    Ok, that's your assignment...but what's your...

    Ok, that's your assignment...but what's your question? What are you having trouble with?

    If you don't know where to start, this might be a good place to begin reading:...
  19. Replies
    16
    Views
    3,285

    If you want more accuracy, maybe use a different...

    If you want more accuracy, maybe use a different data type instead of float?
  20. Replies
    13
    Views
    3,434

    Laziness can often be a virtue in a programmer -...

    Laziness can often be a virtue in a programmer - sometimes it makes the difference between someone who will manually copy and paste many lines of code and change one value per line, and someone else...
  21. Replies
    17
    Views
    9,721

    But how do you know that just because it isn't...

    But how do you know that just because it isn't morse code it is valid input? If I was writing it I would do two checks - one for morse code and if it fails that, one for valid text. Otherwise who...
  22. Replies
    17
    Views
    9,721

    SlyMaelstrom: You could of course read into...

    SlyMaelstrom: You could of course read into another variable, I just figured he wouldn't want to do anything with line if the input was invalid, and if it is valid, line will not change.
    ...
  23. Replies
    17
    Views
    9,721

    line is a character array, you can't compare it...

    line is a character array, you can't compare it to a single char.

    However you can easily test if the line consists only of letters, or only of dots and dashes. You can iterate through the array...
  24. Did you read dwks' post?

    Did you read dwks' post?
  25. charNode *W = start->next->next; charNode* E...

    charNode *W = start->next->next;
    charNode* E = start->next->next;
    You have two pointers to the same node.
Results 1 to 25 of 60
Page 1 of 3 1 2 3