LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-16-2004, 10:47 PM   #1
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Rep: Reputation: 30
error in compiling simple code


Code:
main()

	char data[3];
	int i;
	
	for(i=0;i<3;i++)
	{
		scanf("%c",%data[i]);
		printf("%c",data[i]);
	}
	

}

compiling with gcc,it gives the error----

simple.c: In function `main':
simple.c:14: error: parse error before '%' token
simple.c:19:2: warning: no newline at end of file


plz help
 
Old 09-16-2004, 11:25 PM   #2
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
this might be just from posting the code snippet... but should the line:

scanf("%c",%data[i]);

really have the 'data' array prefixed with a % character?
 
Old 09-17-2004, 12:52 AM   #3
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by jpbarto
[B
really have the 'data' array prefixed with a % character? [/B]
i think yes,it should be there,neway compiling without that didnt give ne +ve results
 
Old 09-17-2004, 01:00 AM   #4
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
the line which is having scanf statement must be
scanf("%c",&data[i]);
 
Old 09-17-2004, 01:09 AM   #5
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Original Poster
Rep: Reputation: 30
hey thnx buddy

but still i get the following error

Code:
simple.c: In function `main':
simple.c:11: error: parse error before "for"
simple.c:9: error: declaration for parameter `i' but no such parameter
simple.c:8: error: declaration for parameter `data' but no such parameter
simple.c: At top level:
simple.c:18: error: parse error before '}' token

Last edited by Tinku; 09-17-2004 at 07:31 AM.
 
Old 09-17-2004, 01:16 AM   #6
rajesh_b
Member
 
Registered: Sep 2004
Location: Hyderabad.
Posts: 83

Rep: Reputation: 15
Modify the program as
#include <stdio.h>
int main()
{
char data[3];
int i;

for(i=0;i<3;i++)
{
scanf("%c",&data[i]);
printf("%c",data[i]);
}


}
 
Old 09-17-2004, 01:38 AM   #7
Tinku
Member
 
Registered: Jul 2004
Location: INDIA
Distribution: SusE, Gentoo,Debian,FreeBSD
Posts: 197

Original Poster
Rep: Reputation: 30
thnx very much,it worked

Last edited by Tinku; 09-17-2004 at 07:32 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Kernel Filter Failed error while compiling packet capturing code on FC2 Prakhardeep Programming 3 08-10-2011 04:55 AM
Interpret this simple C code Chase_G Programming 4 04-29-2005 09:07 AM
Simple Tutorial for compiling source code? SoliTear Linux - Newbie 17 03-15-2004 08:39 AM
simple code *help a newbie out* alimharji Programming 7 03-14-2004 01:23 PM
G++ - why am i getting errors compiling this simple code leroy27336 Programming 4 11-18-2003 08:32 PM


All times are GMT -5. The time now is 03:28 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration