473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C program for reading in a message string

4
Write a C program for reading in a message string (with no blanks)
and decoding the message. Store the decoded message in another string
called outString. After decoding is complete, print the decoded
message. Use the following key for decoding.Convert any numeric
characters in input (0-9) to a space in the output. Upper case letters
in input/message string are decoded by adding 19 to their
ASCII/Integer value. Lower case characters are decoded by adding 9 to
their ASCII value. All other characters (special) are skipped. Count
numeric characters in the input. They become spaces in the
decoded/output string. You also need to count upper and lower case
characters in the input string. At the end print the count of spaces
in the output ( number of numeric characters in input). Also
calculate and print percentage of spaces (blanks) in the OUTPUT
string.

I have written the following code but i m not able to get the decoded
string. rest everything is okie.
please help in correcting that.


I would really appreciate the help.


#include <stdio.h>
#include <stdlib.h>


// Code for function decodeUpper(....)
char decodeUpper(char in_c1)
{char c1;
if (in_c1 + 19 > 'Z' )
{c1 = in_c1 - 'Z' + 'A' - 1 ;}
else
c1 = in_c1 + 19;
return(c1);}


// Code for function decodeLower(....)
char decodeLower(unsigned char in_c2)
{char c2;
if (in_c2 + 9 > 'z')
c2 = in_c2 - 'z' + 'a' - 1 ;
else
c2 = in_c2 + 9;
return c2;}


// Code for function percent(....)
float percent(int m, int n)
{float i;
i = (float)m/n;



}


// Function main begins here.

main ()
{
// In C, string is just an array of characters terminated by '\0'.


char inString[100];
char outString[100];
int i, j;
char c;
int up_count = 0;
int lo_count = 0;
int num_count = 0;
int length;
char p;
// Read input.


printf("Enter a message string with no blanks.\n",inString);
scanf("%s",inString);


// Write a loop for decoding characters of inString.
for(i=0,j=0; inString[i] != '\0'; i++)
{c = inString[i];
if ( c >= 'A' && c <= 'Z' )
{ up_count++;
outString[j] =decodeUpper(c);
j++;}
else{ if ( c >= 'a' && c <= 'z' )
{lo_count++;
outString[j] = decodeLower(c);
j++;}
else {if ( c >= '0' && c <= '9' )
{num_count++;
outString[j] = ' ';
j++;}}}
}


length = num_count + up_count + lo_count;


// Print decoded string.
printf("Decoded Message is :%s\n", outString);


//Print num_count (count of spaces), length of decoded


printf("Length Of Decoded Message is %d\n",length);


printf("Count Of Blanks in Decoded Message is %d \n",num_count);


//Calculate % by calling function percent and print.


printf("%f percent of output is blank\n",100 * percent(num_count ,
length));
Nov 5 '06 #1
0 2230

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Zack Wahab | last post by:
Hi, I use Dev C++ compiler. Tried this program : // Fig. 1.6: fig01_06.cpp // Addition program. #include <iostream> // function main begins program execution int main()
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
3
by: growse | last post by:
Right, I've got a 2 c# programs here. Lets call them A and B. My aim is to send a simple string from B to A. A is always running. I've overridden the WndProc method to give me messages that are...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
1
by: Tony Freixas | last post by:
Hello, I'm trying to create a wrapper for a program. I want to execute program 'X' by running program 'Y', such that 'Y' appears to function pretty much like 'X' both in the way command line...
5
by: rasmidas | last post by:
I have written a file as below: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char* items; int i; for(i=0;i<2;i++)
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
9
by: Keith G Hicks | last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher" project. Starting and stopping the watcher and reading my XML file work fine. Once the watcher is started, I'm reading...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...
0
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...

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.