Search:

Type: Posts; User: never_lose

Page 1 of 2 1 2

Search: Search took 0.01 seconds.

  1. Replies
    29
    Views
    3,363

    Putting a "fgets( buf, BUFSIZ, stdin );" in every...

    Putting a "fgets( buf, BUFSIZ, stdin );" in every case solved that, but that's a lot of duplicate code. I'm thinking there is a better way to do it?
  2. Replies
    29
    Views
    3,363

    Hmm, I've got a pretty good solution now, but not...

    Hmm, I've got a pretty good solution now, but not completely error proof.

    Look what happens if I enter "1 3".




    #include <stdio.h>
    #include <stdlib.h>
    //#define BUFSIZ 100
  3. Replies
    29
    Views
    3,363

    So what is it returning if I enter, say, 2? ...

    So what is it returning if I enter, say, 2?

    What does the 1 represent, and why would I have a problem if it's returning something other than 1, if the while loop is testing for everything other...
  4. Replies
    29
    Views
    3,363

    while( scanf( "%d", &exercises ) != 1 ) What...

    while( scanf( "%d", &exercises ) != 1 )

    What is this checking?
  5. Replies
    29
    Views
    3,363

    I should've said from the beginning that the...

    I should've said from the beginning that the program would be a continuous loop, but I didn't think the loop would add such complications. My fault...


    int main(int argc, char** argv) {

    int...
  6. Replies
    29
    Views
    3,363

    How do I keep 'the crap' out of the read buffer?...

    How do I keep 'the crap' out of the read buffer?

    I tried quzah's option at first, but then when I tried to enter something, it would go to a new line. So I guess I wasn't putting it inside my code...
  7. Replies
    29
    Views
    3,363

    I like CommonTater's solution. But it still...

    I like CommonTater's solution. But it still doesn't work quite right.

    My program continuously loops.



    int main(int argc, char** argv) {

    int exercises;
  8. Replies
    29
    Views
    3,363

    Making a switch error proof

    int exercises;

    scanf("%d", &exercises);

    switch (exercises) {

    case 1: printf("1"); break;
    case 2: printf("2"); break;
    case 3: printf("3"); break;
    ...
  9. Replies
    13
    Views
    2,808

    The values of the characters are stored in...

    The values of the characters are stored in contents[]. So by "mapping them to an array index" do you mean I have to store them in another array?
  10. Replies
    13
    Views
    2,808

    What is an array index, and how would I map a...

    What is an array index, and how would I map a character into one?
  11. Replies
    13
    Views
    2,808

    I have to count the frequency of each character....

    I have to count the frequency of each character. Do I need an array then?
  12. Replies
    13
    Views
    2,808

    I was going to storing them in an array because I...

    I was going to storing them in an array because I was going to compare all the characters to see if they are the same.

    If I want to compare the characters, I would have to store them in an array,...
  13. Replies
    13
    Views
    2,808

    Thanks. I knew it had something to do with the...

    Thanks. I knew it had something to do with the fgetc() being at the EOF but I wasn't sure how to go back to the beginning.
  14. Replies
    13
    Views
    2,808

    Trouble counting digits

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <fcntl.h>
    #include <sys/stat.h>

    int main(int argc, char** argv) {

    FILE *textfile;
    int max_chars = 1000;
  15. Replies
    10
    Views
    7,303

    Thanks, puts() and fread() is what I was looking...

    Thanks, puts() and fread() is what I was looking for. And yeah, I'll have to close the file when I'm done. Thanks for the help.

    EDIT: Oops, I meant puts().
  16. Replies
    10
    Views
    7,303

    Printing contents of a text file

    I'm simply trying to print out the contents of a text file to make sure I am in fact opening and reading a text file correctly. I also want to store all the characters in an array. Here's my code so...
  17. Replies
    2
    Views
    4,616

    Wow. I got it, haha. Thanks!

    Wow. I got it, haha. Thanks!
  18. Replies
    2
    Views
    4,616

    Get a positive/negative input from user

    scanf("%d",&num);
    I can use this to get positive numbers from the user easily.

    But say I also want the user to enter negative numbers, like "-10."

    Obviously I would have to check and see if...
  19. Replies
    2
    Views
    3,584

    Having trouble adding "readline.h"

    #include "readline.h"
    This is at the top of a code that I'm trying to run, but I can't run it because I get this error:



    I'm using NetBeans on Windows 7. I've downloaded the readline 6.2...
  20. Replies
    4
    Views
    1,967

    Ah, thanks! I didn't think fprintf would actually...

    Ah, thanks! I didn't think fprintf would actually write into a file! Interesting. :D
  21. Replies
    4
    Views
    1,967

    Using variables in fwrite

    Say I have a code like this:


    int main() {

    int a=1;
    int b=2;
    int x=3;
    int y=4;
  22. Replies
    17
    Views
    5,675

    Ok, thanks... and what is the purpose of (void)...

    Ok, thanks... and what is the purpose of (void) getchar();?

    Never mind, it must be so that the user can "press enter when ready."

    I've finally finished my program by the way, thanks for the...
  23. Replies
    17
    Views
    5,675

    I'm on Windows. Nothing appears after I hit...

    I'm on Windows. Nothing appears after I hit ctrl+z.

    But when I run this on an Unix machine from my Windows computer it works.

    Any idea why it won't work in Netbeans?
  24. Replies
    17
    Views
    5,675

    Tried Ctrl+Z. After that, enter does nothing, I...

    Tried Ctrl+Z. After that, enter does nothing, I can't type anything, and I can't move the insertion point anywhere.

    I'm using Netbeans. When I compile, it opens in command prompt.
  25. Replies
    17
    Views
    5,675

    In your code, how do I enter after I type...

    In your code, how do I enter after I type something? Pressing enter only goes to a new line.
Results 1 to 25 of 28
Page 1 of 2 1 2