LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2011, 01:22 PM   #31
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723

Quote:
Originally Posted by theNbomr View Post
conio.h sounds like something out of the DOS world. For Linux you will need to use the termios API and/or the ncurses library instead. Time to start learning how to link with external libraries. For details, consult your local man pages.

--- rod.
I don't think that the OP needs anything like ncurses for this project.

It's just that when his friend rewrote the code, he appearantly used conio.h to clear the screen at the start and wait for a key press at the end (probably so that the terminal doesn't close when he launched it from a Windows GUI). Both of those functions are unnecessary and annoying for a Linux command-line app.

Last edited by MTK358; 07-04-2011 at 01:24 PM.
 
1 members found this post helpful.
Old 07-04-2011, 10:23 PM   #32
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
Question

Quote:
Originally Posted by MTK358 View Post
So what you need to do is this:

Code:
char n[100];
char p[100];

scanf("%s, %s", n, p);
The [n] syntax when creating a variable actually puts n amount of variables, one after another, on the stack.
The book I am referring had stated %c as a <format string> to print character in printf() while you have used %s. could you please explain this?


and now The program shows only one error while executing

Quote:
m.c: In function ‘main’:
m.c:24: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
Could some one please explain this error ?
 
Old 07-05-2011, 12:12 AM   #33
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by Nabeel View Post
The book I am referring had stated %c as a <format string> to print character in printf() while you have used %s. could you please explain this?
Your code isn't using %c to print a character. It's using %c to print an array of characters. That's wrong. Use use %s, as we said.
 
Old 07-05-2011, 01:45 AM   #34
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by Nabeel View Post
The program shows only one error while executing
The error you show is not a run-time error message; its a compile-time message (and only a warning, at that). You can also get errors from the linker. C code usually doesn't emit error messages; it just crashes.

--- rod.
 
Old 07-05-2011, 02:38 AM   #35
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
Well the program did got compiled but i got this error while executing the output file

Code:
a.out: 1: Syntax error: "(" unexpected
 
Old 07-05-2011, 03:40 AM   #36
easuter
Member
 
Registered: Dec 2005
Location: Portugal
Distribution: Slackware64 13.0, Slackware64 13.1
Posts: 538

Rep: Reputation: 62
Nabeel, if you want to start out with Python I'd recommend this book:

http://www.greenteapress.com/thinkpy...hinkpython.pdf

It's a great intro both for Python and how to think like a programmer
 
Old 07-05-2011, 03:59 AM   #37
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Quote:
Originally Posted by easuter View Post
Nabeel, if you want to start out with Python
...
from what I can tell he is learning C

I found this tutorial, maybe it helps: http://profesores.fi-b.unam.mx/cintia/ctutor.pdf

Markus
 
Old 07-05-2011, 06:58 AM   #38
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Nabeel View Post
The book I am referring had stated %c as a <format string> to print character in printf() while you have used %s. could you please explain this?
scanf reads, it doesn't write. Also, it doesn't make any sense to read a character (instead of a string) after printing "What is your name? :".

Last edited by MTK358; 07-05-2011 at 07:00 AM.
 
Old 07-06-2011, 01:10 PM   #39
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
Ok I wrote another simple program, which is as follow
Code:
/* Calculating simple Interest*/
/* Author Nbl */
/* Dated 6/7/2011 */
# include <stdio.h>
void main()
{
 int p,n;
 float r,si;
  printf("enter values of p,n,r");
  scanf("%d%d%f,&p,&n,&r");
  si = p*n*r/100;
printf("%f" , si);

}
It did compiled But with the following warning
Code:
m2.c: In function ‘main’:
m2.c:10: warning: too few arguments for format
and upon executing the output file I again got this error.
Code:
a.out: 1: Syntax error: "(" unexpected
 
Old 07-06-2011, 01:24 PM   #40
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Quote:
Originally Posted by Nabeel View Post
Code:
  scanf("%d%d%f",&p,&n,&r);
at least the quotations in your code seem to be wrong.

Note that there is a manpage for any C function, try
Code:
man scanf
in a terminal.

Markus

Last edited by markush; 07-06-2011 at 01:26 PM.
 
Old 07-06-2011, 01:37 PM   #41
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
When looking at the manpage of a function, It's best to use "man 3 function-name" instead of "man function-name". By default, if there is a command with the same name, its manpage will be shown, but "3" tells it to look at C functions only.
 
2 members found this post helpful.
Old 07-06-2011, 01:39 PM   #42
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
@MTK358, thanks for the explanation. You're right. Fortunately the "man scanf" command leads to the manpage in section 3.

Markus
 
Old 07-06-2011, 02:37 PM   #43
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
well I wrote another program that didn't used the scanf() function but I still got the same error when executing it. (it too compiled with no problem)

Here is the program
Code:
#include<stdio.h>


void main()
{

printf("saud rehman\n");
printf("08b-008-te\n");
printf("computer programming principle");

}
 
Old 07-06-2011, 02:40 PM   #44
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
This program works for me. Which errormessage do you get? Which compiler are you using?

Markus
 
Old 07-06-2011, 02:56 PM   #45
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
i Got the following error message
Code:
a.out: 1: Syntax error: word unexpected (expecting ")")
As for the compiler, I am using gcc.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help learning programming Fred_mike Programming 49 10-19-2010 08:52 AM
programming learning way siaswar Programming 5 09-29-2009 11:58 AM
Learning C Programming Trizon Programming 8 03-30-2007 12:37 PM
learning programming nin881 Programming 13 10-19-2005 12:17 AM
C programming learning introuble Programming 7 01-03-2005 11:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration