473,748 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can anyone help me in correcting this code?

4 New Member
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.Conver t 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(cha r 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(uns igned 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",inSt ring);
scanf("%s",inSt ring);


// 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_cou nt ,
length));
Nov 5 '06 #1
0 1414

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

Similar topics

6
5743
by: gsb | last post by:
Don't know if this is the right place to post this JavaScript issue. If not, could someone point me in the right direction please. I am trying to make a "cross browser compliant" floating iFrame. Not real fancy, just load, resize and move. But, I do not have the browsers, OSs and different machines (like Mac) to test the code on. So I need some help to see where this basic example of works and does not work.
12
2414
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my windows forms to a PNG graphic file on my hard drive, I get the following runtime error when I try to run the app: Exception Type: System.Resources.MissingManifestResourceException Message: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly.
0
1709
by: dio_mack | last post by:
MINIMIZE RISK BY CONFIRMING IDENTITY OF INDIVIDUALS Obtain the confidence you need to move forward quickly and accurately in business, institutional and personal matters with a full-spectrum check- including legal name, date of birth, SSN search, current and last known addresses and phone numbers, plus other identity search including birth records and death records. IDENTIFY A PERSON'S LEGAL OR CRIMINAL HISTORY In matters of public record,...
66
3118
by: QuantumG | last post by:
Decompilation is the process of recovering human readable source code from a program executable. Many decompilers exist for Java and .NET as the program executables (class files) maintain much of the information found in the source code. This is not true for machine code executables however. In recent years decompilation for machine code has moved from the domain of crackpots and academic hopefuls to a number of real technologies that...
1
1631
by: vv1 | last post by:
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...
1
1700
by: srinivasarv | last post by:
Dear Friends, kindly help me in correcting the following code This code is for printing the report from the combo box after selection which connects to different reports as selected. I have written this code behind the combo box. Private Sub Bank_Name_AfterUpdate() Dim rpt As String
0
825
by: Blubaugh, David A. | last post by:
To All, Has anyone worked with the F2PY generator? This is something that is supposedly built within numpy and scipy for the Python environment. I was wondering if anyone has encountered any issues with this environment?? This is important to find the answers to these questions.
1
2043
by: Blubaugh, David A. | last post by:
Pauli, Yes, I am utilizing the windows environment. I cannot install f2py. I obtain the following error when I try to execute the setup.py file within the f2py folder located within the numpy master folder: Warning: Assuming default configuration
3
3598
by: graphicssl | last post by:
Okay, so first of all, I'm a designer first and a light coder second (I'm only really trained with HTML and CSS). So I apologize for having to post about something that's probably super-trivial! I'm working on setting up a shopping cart for a one-product web site, and I'm using HTML and CSS, with ASP for the shopping cart. The ASP takes the information from the form on the shopping cart, and formats it in to two e-mails: one for the company...
0
8996
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
9386
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
9333
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
9254
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
8255
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...
1
6799
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
6078
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
4608
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...
3
2217
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.