473,789 Members | 2,598 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 #1
28 2939
fe************* *@tiscali.it wrote:
Hi everybody!
I have this function:

int Scan(char String[])
{
printf("%s", String);
}
You declared the function as returning as int but you don't return
anything. Consider changing it to:
void Scan(char String[]);
it works but when I try to pass a dotted string o separetad with (" ",
"_" , "-" ...ecc)
it return only first word.
Well it should print all the characters in the array upto the first
null character. Certainly dots and dashes should be printed.

Have you checked that your array doesn't contain any null characters
embedded before the end of valid data?
I pass the string in this way:

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

What's wrong?
Until you can show us a complete, compilable example that exhibits your
problem, (copy & paste the code, don't retype it), we can do much more
than keep guessing.

Jul 4 '06 #2
fe************* *@tiscali.it wrote:
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.
It returns nothing; presumably you mean that it prints that.
I pass the string in this way:

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

What's wrong?
Something else.

Post a small, compilable sample of code that demonstrates the problem.
It is not in the uncompilable snippets you posted above.

For example, when I compile and run this program:

#include <stdio.h>

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

int main(void)
{
char CString[] = "I.am.an.exampl e";

Scan(CString);

getchar();
return 0;
}

the result is that I.am.an.example is printed, in its entirety.

Richard
Jul 4 '06 #3

Richard Bos wrote:
fe************* *@tiscali.it wrote:
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.

It returns nothing; presumably you mean that it prints that.
I pass the string in this way:

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

What's wrong?

Something else.

Post a small, compilable sample of code that demonstrates the problem.
It is not in the uncompilable snippets you posted above.

For example, when I compile and run this program:

#include <stdio.h>

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

int main(void)
{
char CString[] = "I.am.an.exampl e";

Scan(CString);

getchar();
return 0;
}

the result is that I.am.an.example is printed, in its entirety.
I don't believe that! (I mean, from you, this little slip.)
(Look at http://snipurl.com/iqxx)

Jul 4 '06 #4
"Suman" <sk*****@gmail. comwrote:
>
Richard Bos wrote:
fe************* *@tiscali.it wrote:
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.
It returns nothing; presumably you mean that it prints that.
I pass the string in this way:
>
char CString[] = "I.am.an.exampl e";
Scan(CString);
>
What's wrong?
Something else.

Post a small, compilable sample of code that demonstrates the problem.
It is not in the uncompilable snippets you posted above.

For example, when I compile and run this program:

#include <stdio.h>

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

int main(void)
{
char CString[] = "I.am.an.exampl e";

Scan(CString);

getchar();
return 0;
}

the result is that I.am.an.example is printed, in its entirety.

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.

Richard
Jul 4 '06 #5
As you want, the original source is...

File Sample.h

void Scan(char String[])
{
printf("%s", String); // this return only 1 word
}
File main.c

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

int main()
{
char SampleString[] = "I.am.a.sample. string";
Scan(SampleStri ng);
return 0;
}
Help me!

Jul 4 '06 #6
fe************* *@tiscali.it wrote:
As you want, the original source is...

File Sample.h

void Scan(char String[])
{
printf("%s", String); // this return only 1 word
}
Why are putting the function definition in a header file? Place the
definition in main.c and only the declaration in Sample.h

By the way, you don't provide a function declaration at all.

Also include a newline character at the end of your printf() format
string. Otherwise, the output is not guaranteed to appear on the output
device.
File main.c

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

int main()
Use the form int main(void)
{
char SampleString[] = "I.am.a.sample. string";
Scan(SampleStri ng);
return 0;
}
The program should print the string correctly. Your code compiles and
behaves as it should on my system. I suggest adding a newline at the
end of the printf() statement in Scan(). What is the exact output that
you're getting?

Jul 4 '06 #7
On 2006-07-04, Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
fe************* *@tiscali.it wrote:
>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.

It returns nothing; presumably you mean that it prints that.
Actually, I wouldn't doubt that some register issue is causing it
to in fact return the first word. Since dropping off the end of a
non-void function is undefined, this is more than plausible.

That and the fact that if this were true, he would be returning a
pointer as an int... the implications of UB are very interesting.

--
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 #8
fe************* *@tiscali.it wrote:
As you want, the original source is...

File Sample.h

void Scan(char String[])
{
printf("%s", String); // this return only 1 word
}
File main.c

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

int main()
{
char SampleString[] = "I.am.a.sample. string";
Scan(SampleStri ng);
return 0;
}
Help me!
No problem here. The program just prints the entire string
'I.am.a.sample. string' and exits.

So what do you think is wrong with it? Have you tested this
code snippet be yourself? Only this snippet, not embedded in
a greater project. Maybe you have some function overloading,
because by the name Scan seems to do something different
than only printing.

Bart
Jul 4 '06 #9
On 2006-07-04, fe************* *@tiscali.it <fe************ **@tiscali.itwr ote:
As you want, the original source is...

File Sample.h

void Scan(char String[])
You should declare, not define, functions in headers. The below belongs
in your .c file.
{
printf("%s", String); // this return only 1 word
I can't imagine how you know that, being as you don't check printf()'s
return value. Also, // is a syntax error in C89, which no doubt you are
supposed to be using.

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

File main.c

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

int main()
int main(void) is clearer.
{
char SampleString[] = "I.am.a.sample. string";
Indent properly with 2 or 4 spaces.
Scan(SampleStri ng);
This function would be better-named Print, no?
return 0;
}

Help me!

Other than that, it compiles cleanly. And it behaves exactly as
others have said that it does.

However, SampleString does not have a \n at the end, and so you
have no guarantee that anything will display at all.

--
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 #10

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

Similar topics

125
14858
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
2838
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
72
5899
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
10183
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
3280
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
4344
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
4263
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
5060
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
2124
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
2149
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
9511
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,...
1
10136
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,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6765
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
5415
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
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
3695
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.