Search:

Type: Posts; User: christophergray

Page 1 of 4 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    28
    Views
    1,944

    scanf("%255s", *in);

    scanf("%255s", *in);
  2. Replies
    7
    Views
    396

    C does not remember the length of a. strlen...

    C does not remember the length of a.

    strlen counts bytes until it reads a NULL, where it stops counting and returns its result.

    A string with a NULL as its first byte is considered empty. In...
  3. Everything stored in the computer is just a bunch...

    Everything stored in the computer is just a bunch of bits turned on or off. Whether it is a letter or number is just a matter of interpretation. You have told scanf to see the bits as an int, and...
  4. Perhaps you could fill your string from the end...

    Perhaps you could fill your string from the end and work your way back in mygetline:


    s[lim] = '\0';
    for (i=lim - 1; i >= 0 && (c=getchar() ) !=EOF && c!='\n'; --i)
    s[i] = c;

    but then...
  5. For a reference, there is this wiki...

    For a reference, there is this wiki, which is available in Ubuntu as devhelp ( apt install cppreference-doc-en-html ) or QT help ( apt install cppreference-doc-en-qch ). For a tutorial, Steve...
  6. char s1[21] = "The grey fox";

    char s1[21] = "The grey fox";
  7. printf("Length of s1 is %lu\n", strlen(s1));

    printf("Length of s1 is %lu\n", strlen(s1));
  8. Do you think it would be good style if the main()...

    Do you think it would be good style if the main() function for the above program consisted of nothing more than an array declaration and four function calls? Or is that going to far?
  9. I started putting curly braces in like this...

    I started putting curly braces in like this because I use a linter (splint) that only understands variable declarations at the start of a block. But it turns out that by reducing the scope of the...
  10. K&R is still one of the best books to learn C. C...

    K&R is still one of the best books to learn C. C really hasn't changed much. Wikipedia has an article on changes in C99.
  11. Deleting line 50, and putting this in place of...

    Deleting line 50, and putting this in place of lines 38-39 will get you first occurance on each line, but not all:
    indexOf(fPtr, newWord, &line, &col);
    while (line != -1) {
    printf("line: %d,...
  12. Replies
    6
    Views
    944

    static void output(struct myStruct weight[], FILE...

    static void output(struct myStruct weight[], FILE * fptr) {
    fprintf(fptr, "\n\nHere is your weight: \n");
    for (int i = 0; i < 4; i++)
    fprintf(fptr, "%d/%d/%d,%f\n",
    ...
  13. But I can return a pointer to an address on the...

    But I can return a pointer to an address on the heap, right? So...
    static char *withoutBar ( char * uri )
    {
    char *out = malloc(256);
    if (out != NULL) {
    size_t i;
    for(i...
  14. I took a look at the assembler output from gcc. ...

    I took a look at the assembler output from gcc. Although I found it hard to read because it is a different format than MASM which also I haven't looked at for 32 years, it looks like your first...
  15. Are you saying it is not an error?

    Are you saying it is not an error?
  16. The local automatic variable s is allocated on...

    The local automatic variable s is allocated on the stack. When the function returns, the stack allocated storage is destroyed. It appears your teacher is not teaching you about lifetime of...
  17. Scanf returns the number of items matched, so if...

    Scanf returns the number of items matched, so if it is less than what you expected (i.e., less than one for the format string "%d") then you have an error.
  18. Replies
    14
    Views
    1,061

    That just means that gcc is not in the PATH.

    That just means that gcc is not in the PATH.
  19. Replies
    3
    Views
    846

    My editor put a squiggly line under a lot of...

    My editor put a squiggly line under a lot of places including line 79 int x,y=0; with the warning "Variable 'x' is not assigned a value." But if you aren't using an editor that does static analysis...
  20. fgets(c, sizeof c, ptrf); if (strcmp(c,...

    fgets(c, sizeof c, ptrf);
    if (strcmp(c, argv[3]))
    fputs(argv[4], ptrs);
    else
    fputs(c, ptrs);
  21. The original poster's code, lines 14, 89-90.

    The original poster's code, lines 14, 89-90.
  22. Replies
    5
    Views
    904

    I don't even know what 0x02 means or what an &...

    I don't even know what 0x02 means or what an & does, but it looks like when you '&' a 0x01 and an 0x02 that you get 0, i.e. false, so your floor=0 assignment is skipped. Also, I'm guessing that you...
  23. scanf("%f", &a);

    scanf("%f", &a);
  24. Replies
    5
    Views
    744

    It makes some sense if you just understand "file...

    It makes some sense if you just understand "file scope" to mean not limited ​to a block or function.
  25. Replies
    9
    Views
    1,004

    They improved BODMAS by adding color, but it is...

    They improved BODMAS by adding color, but it is still a subtile hint--division and multiplication are equal precedence, as are addition and subtraction.
Results 1 to 25 of 82
Page 1 of 4 1 2 3 4