Search:

Type: Posts; User: rstanley

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. For starters change the first line to: ...

    For starters change the first line to:

    #include <stdio.h>
    #include <math.h>

    int main(void){
    ...
    then link in the math library. For gcc add "-lm" to link in the math library.
  2. Replies
    9
    Views
    377

    I completely disagree! If you truly understood...

    I completely disagree!

    If you truly understood pointers, you would know HOW, WHY, and WHEN to pass single pointers, and/or double pointers to a function, and return a pointer for ANY data type!!!...
  3. Replies
    9
    Views
    377

    There are several issues with your concepts of...

    There are several issues with your concepts of the definitions of "list", "node", and "single linked list" as opposed to a "double linked list", or a "circular linked list", so I will not comment any...
  4. Replies
    9
    Views
    377

    head_ref is the address of a linked list pointer...

    head_ref is the address of a linked list pointer that has been defined in the parent function, where new_node will be appended to the list.

    Yes, this can be written much better.

    Rahul11, IMHO,...
  5. You are allocating the memory for the struct...

    You are allocating the memory for the struct three times, and throwing away the memory each time returning from foo()! Allocate the memory BEFORE calling foo(), and pass in the ONE instance of the...
  6. The following is one way to write your code: ...

    The following is one way to write your code:

    #include<stdio.h>
    #include<stdlib.h>

    int main ()
    {
    int *x = malloc(5 * sizeof(*x)); // 5 * sizeof(int) NOT sizeof(int *)

    // NEVER change...
  7. Replies
    11
    Views
    269

    What if you try a lowercase 'c'? fptr =...

    What if you try a lowercase 'c'?

    fptr = fopen("c:\\program.txt","w");
  8. Replies
    11
    Views
    269

    Which compiler are you using? Better answered...

    Which compiler are you using?

    Better answered by a Windoze programmer. I use Linux exclusively.
  9. Replies
    11
    Views
    269

    The basic code works fine under Linux. I don't...

    The basic code works fine under Linux. I don't do Windoze programming anymore, but:

    Try changing:

    fptr = fopen("C:\\program.txt","w");

    to:

    fptr = fopen("program.txt","w");
    And see...
  10. If the "book" you are using to learn C does not...

    If the "book" you are using to learn C does not have a detailed explanation of such a simple concept such as "continue", then you need a much better book, such as one of the three I have specified...
  11. Replies
    15
    Views
    386

    ordak: As well as indenting built into...

    ordak:

    As well as indenting built into programmers editors, such as emacs which I use, among others, or as an add-on to many editors.

    Bottom line, you have many options.
  12. Replies
    15
    Views
    386

    You have to experiment with the various options...

    You have to experiment with the various options to indent, until you get the code to look like you want.

    Work with one or two related options at a time, make notes, then another one or two by...
  13. Replies
    15
    Views
    386

    My response is also valid to the second code...

    My response is also valid to the second code example you provided. It is important to point out errors in any code posted, no matter who actual wrote the code, or if it actually demonstrated a...
  14. Replies
    15
    Views
    386

    The C18 Standard does state: In most O/Ss,...

    The C18 Standard does state:

    In most O/Ss, argc is at least 1, and argv[0] is the program name, or full file path. If argc > 1, then the remainder of the command line arguments are options, file...
  15. Replies
    3
    Views
    188

    I don't use any macs but try: #include...

    I don't use any macs but try:

    #include "misc.h"

    // Instead of:

    #include "./misc.h"

    That is the normal way of including a file in the current directory. The "./" is not needed.
  16. Thread: Word Counting

    by rstanley
    Replies
    10
    Views
    517

    "5 pages of information" for one assignment???...

    "5 pages of information" for one assignment??? Seriously? One page at most, should have been sufficient! Your instructor needs to take a course on assignment creation! I also disagree with the...
  17. Thread: Word Counting

    by rstanley
    Replies
    10
    Views
    517

    Why do you think it is, "how it is supposed to...

    Why do you think it is, "how it is supposed to be"? Where in the instructions does it indicate that punctuation, such as a comma, or a period is part of a "word"??? or where does it indicate that...
  18. Thread: Word Counting

    by rstanley
    Replies
    10
    Views
    517

    "The word, word is a word." I would assume...

    "The word, word is a word."

    I would assume that any whitespace characters and any punctuation, are not part of any "word". Based on this, my example above, should consist of 6 "words", and the...
  19. Thread: Word Counting

    by rstanley
    Replies
    10
    Views
    517

    From the original post: Valid site for a simple...

    From the original post:
    Valid site for a simple word count, but this is a forum for the creation of C programs, and assisting the O/P's with answering their questions, and advising them on their...
  20. If Wait() and main() are in the same file as you...

    If Wait() and main() are in the same file as you show in the first example above, then you don't need a header file. Yes, you could create a header file even if they are in the same file, in...
  21. Replies
    9
    Views
    373

    I am running gcc version 10.2.1, on Debian...

    I am running gcc version 10.2.1, on Debian testing, and -O1, -O2, and -O3, as well as with no -O options, all with -std=c18, and the code runs as you expect it should, and all return 0.

    I cannot...
  22. Thread: macros???

    by rstanley
    Replies
    4
    Views
    308

    Yes, you could use a simple #define macro, but...

    Yes, you could use a simple #define macro, but debugging the code and maintaining it later, especially by a different programmer would be a nightmare! Not recommended!

    Copy & Paste would be a...
  23. If you assign a value to a variable larger than...

    If you assign a value to a variable larger than the maximum value it can hold, it rolls over. Basically it does a modulo, 259%256 == 3
  24. Replies
    20
    Views
    816

    int addition (int a, int b); The int before...

    int addition (int a, int b);

    The int before the function name, "addition" tells the compiler what type is being returned from the function. In this case, the integer type of the local variable,...
  25. Replies
    20
    Views
    816

    First of all, you really need to stop worrying...

    First of all, you really need to stop worrying about using the keyword, "extern" with functions! ALL functions are "extern" by default, so using "extern" on the function declaration or definition,...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4