473,699 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

screwed up programmer

Can anyone tell me what I'm doing here.

#include <stdio.h>
#include "p.h"

extern int show(const char *p){
printf(%c,p);}

Compile into p.o

p.h says
#include <stdio.h>
int show(const char *p);

prog.c says

#include <stdio.h>
#include "p.h"

int main(){
show("hello");}
compile gcc prog.c -o prog

This is all f*cked up. What's wrong with that printf? Go ahead and laugh
and throw tomatoes.

Bill



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #1
5 1442
On Sat, 4 Oct 2003 01:06:42 -0400, "Bill Cunningham" <no****@net.net >
wrote in comp.lang.c:
Can anyone tell me what I'm doing here.

#include <stdio.h>
#include "p.h"

extern int show(const char *p){
printf(%c,p);}
The call to printf() above is certainly wrong. The first argument to
printf() must be a string, perhaps you meant "%c"?

If that's the case the second argument must be a char, which p is not.
p is a pointer to char, which happens to point to the string literal
"hello".

If you wanted to print the first character of that string, you need to
write:

printf("%c", *p);

....*p is a single char, what "%c" needs.

Two other things about your function show...

1. Putting extern on a function declaration, prototype, or definition
is unnecessary and redundant. Unless it contains the static keyword,
it has external linkage.

2. You state that the function will return an int, then you don't
return anything.
Compile into p.o

p.h says
#include <stdio.h>
int show(const char *p);

prog.c says

#include <stdio.h>
#include "p.h"

int main(){
show("hello");}
compile gcc prog.c -o prog

This is all f*cked up. What's wrong with that printf? Go ahead and laugh
and throw tomatoes.

Bill


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #2
Bill Cunningham wrote:
Can anyone tell me what I'm doing here.

#include <stdio.h>
#include "p.h" extern int show(const char *p){
printf(%c,p);}


Syntax error. printf requires a format string, and %c isn't one. "%c", on
the other hand, is one. Your compiler should have told you this. Note that
"%c" would match with a character, not a character string. Perhaps you mean
"%s", or perhaps you mean *p - it's impossible to tell from your code.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #3
Note that
"%c" would match with a character, not a character string. Perhaps you mean "%s", or perhaps you mean *p - it's impossible to tell from your code.

So these 2 prototypes would be alright?

printf("%c",*p) ;
or printf("%s",p);
casting and precedence is my worst enemy in C. When to cast and I seen code
with bunches of parenthesis which is confusing to the beginner. Me anyway.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 13 '05 #4

"Bill Cunningham" <no****@net.net > wrote in message
news:3f******** **@corp.newsgro ups.com...
Note that
"%c" would match with a character, not a character string. Perhaps you

mean
"%s", or perhaps you mean *p - it's impossible to tell from your code.

So these 2 prototypes would be alright?

printf("%c",*p) ;
or printf("%s",p);


Yes, the first prints the first char of where p is pointing to, the second
prints all characters until a '\0' is encountered.
Nov 13 '05 #5
Bill Cunningham wrote:
Note that
"%c" would match with a character, not a character string. Perhaps you mean
"%s", or perhaps you mean *p - it's impossible to tell from your code.

So these 2 prototypes would be alright?

printf("%c",*p) ;
or printf("%s",p);


Those are not prototypes. They are function calls. The first one prints the
first character in the string to which p points. The second prints the
whole string to which p points.
casting and precedence is my worst enemy in C.
I see no casts here, nor do I see any need for them.
When to cast and I seen
code with bunches of parenthesis which is confusing to the beginner. Me
anyway.


Casting is usually wrong, and the places where it's right aren't the places
you'd expect. In good C code, casts are very rare.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1416
by: Steven Wong | last post by:
hi, I've got a pthreaded app, which seg faults. Taking a look at the stack in gdb I notice the "this" pointer gets nulled in the stackframe where the seg fault occurs. Say its in an object, this really messes up things, since trying to access member variables will cause some big problems. What could cause the this pointer to get screwed up like that?
14
1700
by: Sin | last post by:
I've tried everything and I've come to the conclusion that I'm screwed. If anyone can help, I would be eternaly greatful. I have a solution which has 47 projects.. This is includes (very roughly) : 1- plain win32 C++ DLL projects (little over a dozen, refered to as BASE OBJECTS) 2- ATL/COM/C++ DLLs which use the plain win32 DLLs (another dozen, refered to as COM WRAPPERS)
2
1314
by: VB Programmer | last post by:
I had to do a system restore today. I restored it to 2 weeks ago. After it was done I entered VS.NET (latest version) and it said I was entering it for the first time. I opened up a web project I've been working on (ASP.NET 2.0) and I noticed that 2 of the directories were renamed (ex: "Admin" dir to "Admin(2)".) Also, web.config changes I made are now gone. Any ideas why this would happen????
4
2121
by: Jianwei Sun | last post by:
Hi, Not sure what happened. All of my icons in toolbox (VS 2005 IDE) are screwed up. They all look the same with some weird shape. But if I put any of them (like a button, listview ..) on the form, it's still fine. Anybody has some idea what happened to my IDE.
2
1060
by: =?Utf-8?B?UGV0ZXJXb2xmZQ==?= | last post by:
After a clean install o a linsed W2K Prof, I discovered that my 2 other HD's (WDC 200Gb) did contain the musicfiles (all in MP3), did contain the correct names of the albums and even the correct titles of the music of those albums, but when playing these albums/songs I get other music to listen to than I thought I would. I have now 2 HD's as in 2 x 190Gb with music that is free floating, SpaceObServer says it's all there, but I cant get...
0
8631
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8945
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4641
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.