Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I am in desperate need of help with this C code and why it fails to work..?
I am trying to get the C program to work. Whole point of the program is that its supposed to check the strings and reorder them in alphabetical order while ignoring any non alphabetic characters within the strings. My program seems to not do it totally right. Someone help out and it'd be really nice of you.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <string.h>
void vowel (const char * string);
void reorder (int n, char *x[]);
int main () /* Main Function */
{
const char * random = "\nThis is a test run."; /* Const Char string passed as variable random */
printf(random, "%s"); /* Output Statement of 'random' */
vowel(random); /* Calling function 'vowel' */
const char * myname = "\nMy name is Shiva Devarinti."; /* Const Char string passed as variable myname */
printf(myname, "%s"); /* Output Statement of 'myname' */
vowel(myname); /* Calling function 'vowel' */
const char * university = "\nI go to Binghamton University."; /* Const Char string passed as variable university */
printf(university, "%s"); /* Output Statement of 'university' */
vowel(university); /* Calling function 'vowel' */
static char *x[2] = { "Tr2o3phy","Sho2e"}; /* Declaration of array of two pointers */
static char *y[2] = { "Artificial","Art"};
static char *z[2] = { "zoom","Shoe"};
int i;
printf ("\nThe entered strings are:\n"); /* Outputs the entered strings */
for (i = 0; i < 2; ++i)
{
printf ("%s\n", x[i]);
}
printf ("\nThe entered strings are:\n");
for (i = 0; i < 2; ++i)
{
printf ("%s\n", y[i]);
}
printf ("\nThe entered strings are:\n");
for (i = 0; i < 2; ++i)
{
printf ("%s\n", z[i]);
}
int n = 2;
reorder (n, x);
reorder (n, y);
reorder (n, z); /* Sort and reorder the list of strings */
printf("\nThe reordered string is:\n");
for (i = 0; i < n; ++i)
{
printf("\n %d: %s\n", i + 1, x[i]); /* Display the reordered list of strings */
}
printf("\nThe reordered string is:\n");
for (i = 0; i < n; ++i)
{
printf("\n %d: %s\n", i + 1, y[i]);
}
printf("\nThe reordered string is:\n");
for (i = 0; i < n; ++i)
{
printf("\n %d: %s\n", i + 1, z[i]);
}
return 0;
}
void vowel (const char * string) /* Function declaration */
{
int count = 0; /* Variable 'count' Declaration and Initialization */
int store = 0; /* Variable 'store' Declaration and Initialization */
while ( string[count] !='\0') /* Beginning of while loop */
{
/* If an upper case or lower case vowel is encountered add to the variable 'store' and increment it */
if (string[count] == 'A')
++store;
if (string[count] == 'a')
++store;
if (string[count] == 'E')
++store;
if (string[count] == 'e')
++store;
if (string[count] == 'I')
++store;
if (string[count] == 'i')
++store;
if (string[count] == 'O')
++store;
if (string[count] == 'o')
++store;
if (string[count] == 'U')
++store;
if (string[count] == 'u')
++store;
++count;
}
printf ("\nThe Number of vowels in the above sentence are %i.\n", store); /* Output Statement */
}
void reorder (int n, char *x[])
/* Function Declaration */
{
char *temp; /* Variable Declaration */
int i, item;
for (item = 0; item < n - 1; ++item) {
for (i = item + 1; i < n; ++i) {
if (strcmp (x[item], x[i]) > 0) { /* Swapping the strings */
temp = x[item];
x[item] = x[i];
x[i] = temp;
}
}
}
return;
}
2 Answers
- Chris CLv 71 decade agoFavorite Answer
Minimall, fix your printf() statements that look like this:
printf(variable, "%s");
The parameters are backwards, it should be:
printf("%s", variable);
Otherwise, you're destined for a lot of junk moving across your screen.
Secondly, make the if check A LOT easier to read by using a switch statement, instead of many if statements. And I'm still not sure of the purpose of the call to the vowel() function, since it never returns how many vowels there are either through a function return value, or through a global variable.
void vowel (const char * string) /* Function declaration */
{
int count = 0; /* Variable 'count' Declaration and Initialization */
int store = 0; /* Variable 'store' Declaration and Initialization */
while ( string[count] !='\0') /* Beginning of while loop */
{
/* If an upper case or lower case vowel is encountered add to the variable 'store' and increment it */
switch(string[count])
{
case 'A': case 'a':
case 'E': case 'e':
case 'I': case 'i':
case 'O': case 'o':
case 'U': case 'u':
++store;
break;
default: break;
}
++count;
}
- andradesLv 44 years ago
provide the make and form and engine length of the automobile you're engaged on additionally provide greater indicators such because of the fact the automobile motor turning over at a quickly fee without cranking or the starter making a noisy whining noise without the engine turning over. each so often a starter will drag or a the tooth could be broke of the fly wheel. Sounds are important while project capturing. once you turn the change you may in user-friendly terms get a click. On a trip I had a automobile that should crank and close of as quickly as I released the change. It replaced right into a 1977 slant 6 Aspen wagon. It had a fusible link in the run circuit that replaced into open. a guy advised me what the project replaced into and that i used a paper clip to get homestead. somebody will resolve your project in case you provide them adequate tips.