Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A couple of questions about C?
Index -> Programming, C -> C Help
Goto page Previous  1, 2, 3, 4, 5  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
php111




PostPosted: Tue Jan 06, 2009 12:18 pm   Post subject: Re: RE:A couple of questions about C?

DemonWasp @ Tue Jan 06, 2009 11:57 am wrote:
Try it without the remains of the #include directive. That is, remove the < stdio.h > nonsense - that was part of the include. You don't need it.


I am missing characters in my code. I don't see where I am missing. I was comparing my code in Ch to the code in the book. I don't see a different. I see they are the same.

Code from book:



code:
#include <stdio.h>

int main(void)                /* a simple program             */

{

    int num;                  /* define a variable called num */

    num = 1;                  /* assign a value to num        */



    printf("I am a simple "); /* use the printf() function    */

    printf("computer.\n");

    printf("My favorite number is %d because it is first.\n",num);



    return 0;

[/quote]



Clipboard03.jpg
 Description:
 Filesize:  110.46 KB
 Viewed:  117 Time(s)

Clipboard03.jpg


Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue Jan 06, 2009 12:38 pm   Post subject: RE:A couple of questions about C?

I don't see a final }.
php111




PostPosted: Tue Jan 06, 2009 12:49 pm   Post subject: Re: RE:A couple of questions about C?

wtd @ Tue Jan 06, 2009 12:38 pm wrote:
I don't see a final }.




If you don't see a final. Why is it failing to compile my code as shown above?
Vertico




PostPosted: Tue Jan 06, 2009 3:18 pm   Post subject: Re: RE:A couple of questions about C?

php111 @ Tue Jan 06, 2009 1:49 pm wrote:
wtd @ Tue Jan 06, 2009 12:38 pm wrote:
I don't see a final }.




If you don't see a final. Why is it failing to compile my code as shown above?


If you look at the error, then reread wtd's post, it would make more scene.

{

return 0;
}
php111




PostPosted: Tue Jan 06, 2009 3:33 pm   Post subject: Re: A couple of questions about C?

I got the final }. I get more errors. It's never working for me.


Clipboard01.jpg
 Description:
 Filesize:  167.04 KB
 Viewed:  111 Time(s)

Clipboard01.jpg


php111




PostPosted: Tue Jan 06, 2009 3:42 pm   Post subject: Re: A couple of questions about C?

How do I change my syntax file from include to printf? I almost have it.


Clipboard02.jpg
 Description:
 Filesize:  181.47 KB
 Viewed:  121 Time(s)

Clipboard02.jpg


Vertico




PostPosted: Tue Jan 06, 2009 3:49 pm   Post subject: Re: A couple of questions about C?

Re-write the code out in notepad or something, give it correct spacing and indentation.
Trying to look through that is hurting my eyes and it will make it much easier for you to find your mistakes.


Might I also suggest getting away from Ch and use some more native like C?
php111




PostPosted: Tue Jan 06, 2009 4:11 pm   Post subject: Re: A couple of questions about C?

Vertico @ Tue Jan 06, 2009 3:49 pm wrote:
Re-write the code out in notepad or something, give it correct spacing and indentation.
Trying to look through that is hurting my eyes and it will make it much easier for you to find your mistakes.


Might I also suggest getting away from Ch and use some more native like C?


It's hurting mine as well. I'll be 27 in a few weeks. I have bad eyes since birth. I wear glasses. What do you mean by native C? Don't learn C, and go with something else? I really want to learn C but not with Ch. It was recommended to me.
Sponsor
Sponsor
Sponsor
sponsor
php111




PostPosted: Tue Jan 06, 2009 5:09 pm   Post subject: Re: A couple of questions about C?

I tried it in notepad. I am still getting errors. I am just learning. I will post the errors first in a qoute. I will then post my code in code tags.



Quote:
H:/Documents and Settings/baseball> ./cprogramming.c
ERROR: missing ')'
ERROR: syntax error before or at line 7 in file H:\DOCUME~1\baseball\CPROGR~1.C
==>: printf("printf("My favorite number is %d because it is first.\n",num);
BUG: printf("printf("My<== ???
ERROR: missing "
ERROR: cannot execute command 'H:\DOCUME~1\baseball\CPROGR~1.C'
H:/Documents and Settings/baseball>





code:
int main(void) /* a simple program */
{
int num; /* define a variable called num */
num = 1; /* assign a value to num */
printf("I am a simple "); /* use the printf() function */
printf("computer.\n");
printf("printf("My favorite number is %d because it is first.\n",num);


return 0;
Vertico




PostPosted: Tue Jan 06, 2009 5:31 pm   Post subject: Re: A couple of questions about C?

php111 @ Tue Jan 06, 2009 6:09 pm wrote:



printf("printf("My favorite number is %d because it is first.\n",num);

[/code]


You have written printf twice. You also missed the end }




c:
int main(void) /* a simple program */
{
int num; /* define a variable called num */
num = 1; /* assign a value to num */
printf("I am a simple "); /* use the printf() function */
printf("computer.\n");
printf("My favorite number is %d because it is first.\n",num);


return 0;

}


[/code]


Ch is some sort of rework of the C language. I know nothing about it other then what I have seen in this thread, but it seems to be some sort of learning tool?
I am suggesting you use/write C in the traditional scene.

Open an IDE/Editor (like notepad) type all your code in there, save it with the extension .c (ex. helloWorld.c ) then compile and run the code through either the IDE or command prompt.
php111




PostPosted: Tue Jan 06, 2009 5:54 pm   Post subject: Re: A couple of questions about C?

I done it!!!!!

I used ./the name of my file.c in Ch. I wrote the code using notepad. That was easier then using Ch to write it.

Should I keep writing the same code, or move on? If I write it again then I just delete that code.

Thank you everyone who replied. I wait to see to rewrite or continue.



Clipboard03.jpg
 Description:
 Filesize:  98.98 KB
 Viewed:  115 Time(s)

Clipboard03.jpg


Vertico




PostPosted: Tue Jan 06, 2009 7:17 pm   Post subject: Re: A couple of questions about C?

Congratulations!

Your best bet would be to continue to build off what you know. Perhaps try some arithmetic (add / subtract / divide / multiple your variables)
Learn how to use scanf() (Read formatted data)

The more and more you learn, the easier these last few steps will seem to you.
php111




PostPosted: Tue Jan 06, 2009 7:29 pm   Post subject: Re: A couple of questions about C?

Vertico @ Tue Jan 06, 2009 7:17 pm wrote:
Congratulations!

Your best bet would be to continue to build off what you know. Perhaps try some arithmetic (add / subtract / divide / multiple your variables)
Learn how to use scanf() (Read formatted data)

The more and more you learn, the easier these last few steps will seem to you.


Do I do that with that printf code above? If so, how do I do that?
Vertico




PostPosted: Tue Jan 06, 2009 7:48 pm   Post subject: Re: A couple of questions about C?

Quick examples:

c:
//Addition and Subtraction of integers

#include <stdio.h>

int main ()
{

        int firstNumber = 3, secondNumber = 2, thirdNumber = 0;
        int inputNumber = 0;


        printf("This is a test file \n");

        //Adding secondNumber to firstNumber
        thirdNumber = firstNumber + secondNumber;
       
        printf("%d plus %d equals %d. \n", firstNumber, secondNumber, thirdNumber);

        //Subtracting secondNumber from firstNumber
        thirdNumber = firstNumber - secondNumber;
       
        printf("%d subtract %d equals %d. \n", firstNumber, secondNumber, thirdNumber);

       

        return 0;
}


c:
//Getting integer input from user.

#include <stdio.h>

int main ()
{

        int firstNumber = 0;

        printf ("Enter in a integer : ");
       
       //scanf is used to get input from the user, then places the value into the variable firstNumber
        scanf("%d", &firstNumber);

        printf ("You entered in %d.\n", firstNumber);

       

        return 0;
}
php111




PostPosted: Tue Jan 06, 2009 8:35 pm   Post subject: Re: A couple of questions about C?

I got a whole list of errors with your first code.

My errors:


Quote:
H:/Documents and Settings/baseball> test1.c
ERROR: maybe missing ';'
ERROR: syntax error before or at line 3 in file test1.c
==>: int firstNumber = 3 secondNumber = 2 thirdNumber = 0;
BUG: int<== ???
ERROR: variable 'thirdNumber' not defined
ERROR: command 'thirdNumber' not found
ERROR: syntax error before or at line 7 in file test1.c
==>: thirdNumber = firstNumber + secondNumber
BUG: thirdNumber = firstNumber + secondNumber<== ???
ERROR: variable 'thirdNumber' not defined
ERROR: command 'thirdNumber' not found
ERROR: syntax error before or at line 11 in file test1.c
==>: thirdNumber = firstNumber - secondNumber;
BUG: thirdNumber = firstNumber - secondNumber;<== ???
ERROR: cannot execute command 'test1.c'
H:/Documents and Settings/baseball>






My code:


code:
#include <stdio.h>
int main()
int firstNumber = 3 secondNumber = 2 thirdNumber = 0;

printf("This is a test file \n");

thirdNumber = firstNumber + secondNumber

printf("%d plus %d \n", firstNumber, secondNumber, thirdNumber);

thirdNumber = firstNumber - secondNumber;

printf("%d subtract %d equals %d \n", firstNumber, secondNumber, thirdNumber);
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 4 of 5  [ 72 Posts ]
Goto page Previous  1, 2, 3, 4, 5  Next
Jump to:   


Style:  
Search: