473,802 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong?

Hi everybody!
I have this function:

int Scan(char String[])
{
printf("%s", String);
}

it works but when I try to pass a dotted string o separetad with (" ",
"_" , "-" ...ecc)
it return only first word.
I pass the string in this way:

char CString[] = "I.am.an.exampl e";
Scan(CString);

What's wrong?
Help me please!
Thx!

Jul 4 '06
28 2943
Andrew Poelstra <ap*******@loca lhost.localdoma inwrote:
On 2006-07-04, fe************* *@tiscali.it <fe************ **@tiscali.itwr ote:
{
printf("%s", String); // this return only 1 word
Also, that statement is equivilant to puts (string); which is likely more
efficient, not to mention easier to read.
Not quite. That would be printf("%s\n", String);.

Richard
Jul 4 '06 #11
Andrew Poelstra wrote:
On 2006-07-04, fe************* *@tiscali.it <fe************ **@tiscali.itwr ote:
>>As you want, the original source is...
[...]
printf("%s", String); // this return only 1 word
[...]
Also, that statement is equivilant to puts (string); which is likely more
efficient, not to mention easier to read.
Not quite equivalent: puts() adds a newline.

--
Eric Sosman
es*****@acm-dot-org.invalid
Jul 4 '06 #12
On 2006-07-04, Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
Andrew Poelstra <ap*******@loca lhost.localdoma inwrote:
>On 2006-07-04, fe************* *@tiscali.it <fe************ **@tiscali.itwr ote:
{
printf("%s", String); // this return only 1 word
>Also, that statement is equivilant to puts (string); which is likely more
efficient, not to mention easier to read.

Not quite. That would be printf("%s\n", String);.
His original statement /should/ have been printf ("%s\n", String); and
that was likely the cause of his original problem.

You are correct, though; I completely missed that. Guess I was looking
at the intent of the code instead of the actual code... good thing we
have quick compilers nowadays.

--
Andrew Poelstra <http://www.wpsoftware. net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris
Jul 4 '06 #13
Andrew Poelstra <ap*******@loca lhost.localdoma inwrites:
On 2006-07-04, Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
>Andrew Poelstra <ap*******@loca lhost.localdoma inwrote:
>>On 2006-07-04, fe************* *@tiscali.it
<fe********** ****@tiscali.it wrote:
{
printf("%s", String); // this return only 1 word
>>Also, that statement is equivilant to puts (string); which is likely more
efficient, not to mention easier to read.

Not quite. That would be printf("%s\n", String);.

His original statement /should/ have been printf ("%s\n", String); and
that was likely the cause of his original problem.
Actually, I'd be surprised if that were the case. It's
implementation-defined whether the newline is required, and if it is
required and you don't supply it then printing a single word is one
legal consequence. But realistically, I doubt that any system the OP
is likely to be using actually does require the newline, and even if
it does, I'd expect the error to appear as nothing being printed at
all.

The OP needs to add the newline and try again, and he needs to
understand the difference between returning something and printing
something.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 4 '06 #14
On 2006-07-04, Keith Thompson <ks***@mib.orgw rote:
Andrew Poelstra <ap*******@loca lhost.localdoma inwrites:
>On 2006-07-04, Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
>>Andrew Poelstra <ap*******@loca lhost.localdoma inwrote:
On 2006-07-04, fe************* *@tiscali.it
<fe********* *****@tiscali.i twrote:
{
printf("%s", String); // this return only 1 word

Also, that statement is equivilant to puts (string); which is likely more
efficient, not to mention easier to read.

Not quite. That would be printf("%s\n", String);.

His original statement /should/ have been printf ("%s\n", String); and
that was likely the cause of his original problem.

Actually, I'd be surprised if that were the case. It's
implementation-defined whether the newline is required, and if it is
required and you don't supply it then printing a single word is one
legal consequence. But realistically, I doubt that any system the OP
is likely to be using actually does require the newline, and even if
it does, I'd expect the error to appear as nothing being printed at
all.
Out of all the problems with his code, the missing \n seemed the most
likely cause of invalid output. Falling off of the int-returning
function occured /after/ the printf, and most of the other issues were
style-related.

Also, consider that everyone else who tried his code got correct results;
this suggests that the OP was using some uncommon platform or compiler.
But of course that's just speculation on my part.
The OP needs to add the newline and try again, and he needs to
understand the difference between returning something and printing
something.
Absolutely true.

--
Andrew Poelstra <http://www.wpsoftware. net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris
Jul 4 '06 #15

Richard Bos wrote:
"Suman" <sk*****@gmail. comwrote:
[code relying on imp. defined behavior]
I don't believe that!

You are free to disbelieve that the earth is pentangular, for all I
care. I wrote that when _I_ run that program, it prints the entire
string; and it does. As for the final newline, the cursor does indeed
start after the printed string, without a newline in between, and a
newline is only printed when I press enter; this is one legal result of
the program.
<fumes>
I don't understand why you'd need such an analogy, for all _I_ care.
Simply
put, I expect one to be atleast as vigilant as you expect the others to
be.
Slip-ups happen, you'd better take them in stride.
</fumes>

Jul 4 '06 #16
On 2006-07-04, Suman <sk*****@gmail. comwrote:
>
Richard Bos wrote:
>"Suman" <sk*****@gmail. comwrote:
[code relying on imp. defined behavior]
I don't believe that!

You are free to disbelieve that the earth is pentangular, for all I
care. I wrote that when _I_ run that program, it prints the entire
string; and it does. As for the final newline, the cursor does indeed
start after the printed string, without a newline in between, and a
newline is only printed when I press enter; this is one legal result of
the program.

<fumes>
I don't understand why you'd need such an analogy, for all _I_ care.
If you reorganize that sentence, you said "For all I care, I don't
understand..." (I didn't change the grammatical meaning whatsoever).
Simply
put, I expect one to be atleast as vigilant as you expect the others to
be.
Keith is much more vigilant than he expects most people to be. For
example, I can't imagine that he expects much from you.
Slip-ups happen, you'd better take them in stride.
In most cases, it's best to stop and fix slip-ups, especially in
mission-critical code. That isn't what "take in stride" means, just
so you know.
></fumes>
Being angry is no way to get help; step away from the keyboard for
a few hours.

--
Andrew Poelstra <http://www.wpsoftware. net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris
Jul 4 '06 #17

Andrew Poelstra wrote:
On 2006-07-04, Suman <sk*****@gmail. comwrote:

Richard Bos wrote:
"Suman" <sk*****@gmail. comwrote:
[ ...]
<fumes>
I don't understand why you'd need such an analogy, for all _I_ care.

If you reorganize that sentence, you said "For all I care, I don't
understand..." (I didn't change the grammatical meaning whatsoever).
I wanted to know why Richard Bos needed that analogy. Period.
Simply
put, I expect one to be atleast as vigilant as you expect the others to
be.

Keith is much more vigilant than he expects most people to be. For
example, I can't imagine that he expects much from you.
I thought I had quoted enough to tell _anyone_ I was replying to
Richard Bos.
Slip-ups happen, you'd better take them in stride.

In most cases, it's best to stop and fix slip-ups, especially in
mission-critical code. That isn't what "take in stride" means, just
so you know.
Re-read. For all you know, you might start reading a bit more into my
post.

Being angry is no way to get help; step away from the keyboard for
a few hours.
Where are you? (I mean, are you having difficulty following the thread?)

Jul 4 '06 #18
On 2006-07-04, Suman <sk*****@gmail. comwrote:
>
Andrew Poelstra wrote:
>On 2006-07-04, Suman <sk*****@gmail. comwrote:
>
Richard Bos wrote:
"Suman" <sk*****@gmail. comwrote:
[ ...]
><fumes>
I don't understand why you'd need such an analogy, for all _I_ care.

If you reorganize that sentence, you said "For all I care, I don't
understand.. ." (I didn't change the grammatical meaning whatsoever).
I wanted to know why Richard Bos needed that analogy. Period.
Which analogy? If you mean the pentagonal earth one, I think he was trying
to help you understand that you can't respond to helpful replies with "I
don't believe you" and expect to be taken seriouly.
Simply
put, I expect one to be atleast as vigilant as you expect the others to
be.

Keith is much more vigilant than he expects most people to be. For
example, I can't imagine that he expects much from you.
I thought I had quoted enough to tell _anyone_ I was replying to
Richard Bos.
My mistake! I was working on another thread in which Keith Thompson
was involved.
Slip-ups happen, you'd better take them in stride.

In most cases, it's best to stop and fix slip-ups, especially in
mission-critical code. That isn't what "take in stride" means, just
so you know.
Re-read. For all you know, you might start reading a bit more into my
post.
I read some helpful replies, and I read you refusing them. I certainly
can't see how it would be worth my time to go reread those; I myself
pointed out the problems with your code.
>

Being angry is no way to get help; step away from the keyboard for
a few hours.

Where are you? (I mean, are you having difficulty following the thread?)
No, I just didn't read the attribution line. Mistakes happen. Take them
in stride. :-)

--
Andrew Poelstra <http://www.wpsoftware. net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris
Jul 4 '06 #19
On 4 Jul 2006 13:28:48 -0700, in comp.lang.c , "Suman"
<sk*****@gmail. comwrote:
>
Andrew Poelstra wrote:
>On 2006-07-04, Suman <sk*****@gmail. comwrote:
>
Richard Bos wrote:
"Suman" <sk*****@gmail. comwrote:
[ ...]
><fumes>
I don't understand why you'd need such an analogy, for all _I_ care.

If you reorganize that sentence, you said "For all I care, I don't
understand.. ." (I didn't change the grammatical meaning whatsoever).

I wanted to know why Richard Bos needed that analogy. Period.
Then you might want to have said that. What you instead said was "I
don't understand why you need that analogy, I don't care". Which makes
no sense!
Slip-ups happen, you'd better take them in stride.

In most cases, it's best to stop and fix slip-ups, especially in
mission-critical code. That isn't what "take in stride" means, just
so you know.

Re-read. For all you know, you might start reading a bit more into my
post.
Frankly, as a native english speaker, I was pretty confused as to what
you meant.

By teh way, if you plan to criticize people's code, you should make
your criticism explicit. "I don't believe you" and "I expect you to be
vigilant" without any supporting evidence does not give anyone any
reason to take your posts seriously.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jul 4 '06 #20

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

Similar topics

125
14865
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
5
2840
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
72
5905
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
121
10192
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
28
3284
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr(); fopen("c:\\autoexec.bat","r")&&printf("success") || printf("error opeing
56
4347
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on C. wat type of questions should be expected? Which part of C language do the staff give more concern? The interviewers have just mentioned that .. i will have interview on C. Also can anyone can help me with sites where i can go thru sample
46
4264
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
13
5063
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
2126
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
3
2152
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when Record (i) is shown and modified, the change will come to Record (i+1). Can anyone provide suggestion? thanks.
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
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
7598
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
6838
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
5494
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...
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.