Noobie in C


 
Thread Tools Search this Thread
Top Forums Programming Noobie in C
# 1  
Old 12-23-2009
Noobie in C

Hi to everyone , I am learning C language and I have problem with one example from book

Code:
#include <stdio.h>
int main()
{
   char me[20];
   printf(“What is your name?”);
   scanf(“%s”,&me);
   printf(“Welcome, %s!\n”,me);
   return(0);
}

Code:
                                when I want to compile returns me 
whoru.c: In function ‘main’:
whoru.c:6: error: stray ‘\342’ in program
whoru.c:6: error: stray ‘\200’ in program
whoru.c:6: error: stray ‘\234’ in program
whoru.c:6: error: expected expression before ‘%’ token
whoru.c:6: error: stray ‘\342’ in program
whoru.c:6: error: stray ‘\200’ in program
whoru.c:6: error: stray ‘\235’ in program
whoru.c:6: warning: format not a string literal and no format arguments

# 2  
Old 12-23-2009
Hi,

It looks like the quotes are wrong (i.e. incorrect characters). This sometimes happens when copy&pasting from browsers and certain word-processors. Make sure that you use " (ASCII 34).

Cheers,

Andy Barry
Nooleus.com
App Launcher for Sys Admins
# 3  
Old 12-23-2009
Looked and C code is O.K
# 4  
Old 12-23-2009
There are "wide" characters in your C script. Possibly due to locale settings.

Valid characters in C are ASCII 0 -> ASCII 127, single byte characters - you have an octal 342 character in your code script which is way outside those bounds, for example.

Did you use an editor on a PC, then copy to UNIX?
# 5  
Old 12-23-2009
Code:
#include <stdio.h>
int main()
{
   char me[20];
   printf(“What is your name?”);
   scanf(“%s”,me);
   printf(“Welcome, %s!\n”,me);
   return(0);
}

but strange is that I can compile primary code in Fedora using gcc Smilie
# 6  
Old 12-27-2009
Code:
scanf(%s,&me);

Change those formatted quotes to straight quotes and remove the &
scanf() with strings do not receive an & since it is a pointer to the first character already.
Either
Code:
scanf("%s", me);

or
Code:
scanf("%s", &me[0]);

But the fact is that for getting string input from user, scanf() is a poor choice.
Code:
fgets()

would server you better.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help while looping simple noobie

hi guys i have linked my lab 15. i have no idea where to start i dont understand whats it asking me. about the screen shot part!.. if someone can take a quick look and help me out with this unix lab that would be great.. i have did the Required Errorlevels Errorlevel #Event Information ... (1 Reply)
Discussion started by: beerpong1
1 Replies

2. Windows & DOS: Issues & Discussions

Noobie with Linux emu: Need help with emu's

Hi i have recently downloaded the cygwin emulator on my windows xp machine and i installed it onto my laptop and all was fine. The thing is i have never known how to use it really. I am wanting to use linux on windows since i have some programs that work on linux only. I have a program called... (1 Reply)
Discussion started by: Sharkadder
1 Replies

3. UNIX for Dummies Questions & Answers

I need help with a noobie shell script.

My applogies. (1 Reply)
Discussion started by: buttons
1 Replies

4. UNIX for Dummies Questions & Answers

Network noobie question

This is my first attempt in installing a netbsd ever. I'm trying to get myself familiar with some commands and how things work in unix and so far i never knew its this fun. Anyway, unix is our elective here in school and school is gonna start 2 weeks. I'm just trying to get a headstart on this :D... (2 Replies)
Discussion started by: 3rr0r_3rr0r
2 Replies

5. Solaris

New born noobie with an easy question

I was told on a website that unix can help you make one. I was just wondering how and can you help me with a web page of my own. (1 Reply)
Discussion started by: Shintouku
1 Replies

6. UNIX for Dummies Questions & Answers

Unix Noobie Needs help with scripting

I've just begun using/studying Unix and I've run into a problem. I'm attempting to write a script that will replace a string within a textfile with another string, backing up the file before editing it. This is what I have so far, but I'm getting a "command not found" error. example input: ... (2 Replies)
Discussion started by: Vamirr
2 Replies
Login or Register to Ask a Question