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 1744
In article <j8************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote: On Wed, 16 Nov 2005 21:15:55 GMT, in comp.lang.c , Keith Thompson <ks***@mib.org > wrote:
ga*****@yin.i nteraccess.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.
I see what you're saying, but, hey, call me a masochist, but I find Keith
amusing. 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: 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: 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,...
|
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...
|
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...
|
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...
| |