I need the following code to return a string of character stored in
array and also return the size of the array. I want to do it without
using pointers and so far have the character storing working fine, it's
just that I can't really think of a way to return the number of
characters in the array. Anyone help me out?
int inputPhrase()
{
char msg[characters], ch;
int i = 0;
int n = 5;
while ((ch = getchar()) != '\n')
{
msg[i++] = ch;
}
msg[i] = '\0'; /* prevents garbage from being place at end of array
output */
i = 0;
while (msg[i] != '\0')
{
printf("%c", msg[i++]);
}
return n;
}
int main()
{
inputPhrase();
int size = inputPhrase();
printf("%d\n", size);
return 0;
}
Nov 15 '05
20 1745
tigrfire wrote: I've modified my code as you mentioned and also made some syntatical changes that Jack recommended. I'm now trying to do a number of things with my code: 1. I'm writing a function called cleanUpPhrase that removes punctuation and whitespace. I'm going to try and accomplish this using tolower() and isAlpha() from the ctype library I've included. I'm just a little confused on how I can pass the string of chars from my inputPhrase function into my cleanUpPhrase function. 2. On another note, I'm also trying to modify my inputPhrase function so that if the user-inputted string of chars is longer than 30 chars long, it will truncate the message and only output the first 30 chars. In my main function I used an if loop to truncate the size, but nothing I've tried in my inputPhrase function to truncate the actual returned message output is working.
Here's the code:
/* BEGIN new.c */
#include <stdio.h>
#include <ctype.h>
#define MAX_CHARS 30
size_t inputPhrase(cha r *msg, size_t max);
int main(void)
{
char msg[MAX_CHARS + 1];
size_t size;
size = inputPhrase(msg , sizeof msg - 1);
printf("\n%u\n" , (unsigned)size) ;
puts(msg);
return 0;
}
size_t inputPhrase(cha r *msg, size_t max)
{
size_t i;
int ch;
ch = getchar();
for (i = 0; max > i && ch != '\n' && ch != EOF; ++i) {
msg[i] = (char)ch;
ch = getchar();
}
msg[i] = '\0';
return i;
}
void cleanUpPhrase()
{
}
/* END new.c */
--
pete
On 14 Nov 2005 18:34:00 -0800, in comp.lang.c , "tigrfire"
<bb******@gmail .com> wrote: Outside the function I defined characters as: #define characters 30
(and other contextless remarks)
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
tigrfire wrote: I've modified my code as you mentioned and also made some syntatical changes that Jack recommended. I'm now trying to do a number of things with my code: 1. I'm writing a function called cleanUpPhrase that removes punctuation and whitespace. I'm going to try and accomplish this using tolower() and isAlpha() from the ctype library I've included.
There's also ispunct() and isspace() to consider.
--
pete
In article <ec************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote: On 14 Nov 2005 18:34:00 -0800, in comp.lang.c , "tigrfire" <bb******@gmai l.com> wrote:
Outside the function I defined characters as: #define characters 30
(and other contextless remarks)
-- Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header.
You (and others, such as Keith) are wasting your breath. They'll never get
it. And I'll tell you why.
Imagine that there's a mouse - and the mouse is the Usenet. You and I can
see that it is a mouse and we behave accordingly. But now there is a class
of users (we'll call them "googlers") that are wearing these funny weird
glasses that make them see not a mouse, but an elephant. Seeing an
elephant (i.e., the Usenet as a web page), they also behave accordingly.
And no amount of verbiage from us is going to convince them that it's not
an elephant - that it is only a mouse.
To make this more clear, to a googler, it doesn't make any sense to "quote"
(whatever the heck that is...), in fact, to do so would be absurd, when all
the rest of the articles in the thread are right there in front of their
faces (just as clear as the trunk on that mouse, er, elephant). And no
amount of verbiage from us is going to convince them not to believe what
they see. The point is you can *never* convince someone that what they see
isn't reality. The only way you can address the problem is to help them
fix their eyesight (or help them remove their funny glasses).
Or, just let it go... ga*****@yin.int eraccess.com (Kenny McCormack) writes: In article <ec************ *************** *****@4ax.com>, Mark McIntyre <ma**********@s pamcop.net> wrote:On 14 Nov 2005 18:34:00 -0800, in comp.lang.c , "tigrfire" <bb******@gma il.com> wrote:
Outside the function I defined characters as: #define characters 30
(and other contextless remarks)
-- Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header.
You (and others, such as Keith) are wasting your breath. They'll never get it. And I'll tell you why.
You've told us why several times before. We've explained why you're
wrong (briefly, many of them *do* get it). Save your own breath.
--
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.
On Wed, 16 Nov 2005 21:15:55 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.or g> wrote: ga*****@yin.in teraccess.com (Kenny McCormack) writes:
(the usual nonsense) You've told us why several times before. We've explained why you're wrong (briefly, many of them *do* get it). Save your own breath.
I don't see why you don't killfile the idiot. He rarely says anything
worth listening to, and is erroneous insufficiently often to endure
just so you can correct him.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
On Wed, 16 Nov 2005 21:15:55 GMT, in comp.lang.c , Kenny McCormack
wrote: You (and others, such as Keith) are wasting your breath.
I dont use my breath to power my computer. I don't emit that sort of
quantity of hot air....
(sorry, the threading may get hosed on this, Kenny's in my killfile so
I had to reply to Keith and update the attrib line).
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.or g> wrote:
.... You've told us why several times before. We've explained why you're wrong (briefly, many of them *do* get it). Save your own breath.
Au contraire. 'tis you that is wrong.
And that is why I must keep posting. To set the record straight each time.
Kenny McCormack wrote: Au contraire. 'tis you that is wrong.
And that is why I must keep posting. To set the record straight each time.
Actually, people get it as long as there's someone to correct them
often. Google made it
easier for people to get on nntp groups but many, even people who posted
before using
an Usenet client and switched to Google groups don't realize that the
Reply link doesn't
work properly, and that it doesn't hide but it totally annihilates the
original
message. Also, warning people about top posting is a good idea not
necessarily for the sake
of the guys who post but for the people who bother to read. People
coming to a newsgroup
looking for an answer to a question should be aware that if someone
bothers to read
they should also use common sense when replying.
This discussion will degenerate into a children's fight... someone wants
to have the last word
even if he's not right. If you have the will to post to fight something
that makes no sense, why not
So why not let people warn others if they are willing to do that?
I hope I won the war and have the last post on this :-).
>many, even people who posted before using an Usenet client and switched to Google groups don't realize that the Reply link doesn't work properly, and that it doesn't hide but it totally annihilates the original message.
just for sake of information, the reply link at bottom is quick reply
don't use it. instead near the name of poster, on top of message, click
options, then reply...
Also, warning people about top posting is a good idea not necessarily for the sake of the guys who post but for the people who bother to read.
That's really a good idea...
People coming to a newsgroup looking for an answer to a question should be aware that if someone bothers to read they should also use common sense when replying.
alas! it's not that common :P.
This discussion will degenerate into a children's fight... someone wants to have the last word even if he's not right.
:D
If you have the will to post to fight something that makes no sense, why not So why not let people warn others if they are willing to do that? I hope I won the war and have the last post on this :-).
let's see. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wynand Winterbach |
last post by:
I think every C programmer can relate to the frustrations that malloc
allocated arrays bring. In particular, I've always found the fact that
the size of an array must be stored separately to be a nightmare.
There are of course many solutions, but they all end up forcing you to
abandon the array syntax in favour of macros or functions.
Now I have two questions - one is historical, and the other practical.
1.) Surely malloc (and...
|
by: Jonathan |
last post by:
I have a client solution that requires data and associated files to be
stored with data in a database. As such, I have a situation where JPEG
thumbnails/images that are stored as BLOBs (image data-type) in a SQL DB
need to be written to an ASP.NET page. The BLOB is actually wrapped by a
class written in C#, BlobObj, which can return a byte-array containing the
image-bytes. I can successfully write the image to the page using the...
|
by: awebguynow |
last post by:
I know its redundant but thats what this report calls for.
For every node except the first, I want to output a pair of nodes: the
current and prev one.
For sake of example, lets call the node <qsales> Quarterly Sales. (and
includes children)
If I could use an array syntax, it would be:
<qsales>
<qsales>
|
by: manochavishal |
last post by:
Hi,
I have a question.
How can i know the size of array when it is passed to a function.
For Example i have this code:
#include <stdio.h>
#include <stdlib.h>
|
by: superja |
last post by:
I have some problem outputting double variable types.
Below is my script:
#include <stdio.h>
#include <math.h>
double x;
double h;
| |
by: bowlderster |
last post by:
Hello,all.
I want to get the array size in a function, and the array is an argument of the function.
I try the following code.
/***************************************
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
|
by: Peter Nimmo |
last post by:
Hi,
I am writting a windows application that I want to be able to act as if
it where a Console application in certain circumstances, such as error
logging.
Whilst I have nearly got it, it doesn't seem to write to the screen in
the way I would expect.
The output is:
|
by: Matt |
last post by:
Hello. I'm having a very strange problem that I would like ot check
with you guys.
Basically whenever I insert the following line into my programme to
output the arguments being passed to the programme:
printf("\nCommand line arguement %d: %s.", i , argv );
The porgramme outputs 3 of the command line arguements, then gives a
segmentation fault on the next line, followed by other strange
|
by: mohaakilla51 |
last post by:
Alright guys, I am working on a flashcard script... Previously I had it so that it onlty had predefined categories. People were complaining, so now I am trying to make it to where it reads flashcards.txt and then gets the categories from there.
Anyhow, I understand how to do this, and there is nothing wrong with my syntax, because it compiles properly, but whenever it runs, it just starts outputting a bunch of random text, although I did...
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |