What is wrong with this computer science program? I have an error at line 22, saying "identifier 'gets' is undefined". How do I fix this?
#include<stdio.h>
#include<string.h>
int countvowel(char* str) {
int i = 0, count = 0;
while (str[i] != '\0') {
if (str[i] == 'A' || str[i] == 'E'
|| str[i] == 'I' ||
str[i] == 'O' ||
str[i] == 'U' || str[i] == 'a' ||
str[i] == 'e' ||
str[i] == 'i' || str[i] == 'o' ||
str[i] == 'u')
{
count++;//count
vowels
}
i++;
}
return count;
}
int main()
{
int n;
char str[100];
printf("Enter a string for count vowels: ");
gets(str); //take input a string from user
n = countvowel(str); //Call the function to count
vowels
printf("\n No. of vowels are : %d", n);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int countvowel(char* str) {
int i = 0, count = 0;
while (str[i] != '\0') {
if (str[i] == 'A' || str[i] == 'E' || str[i] == 'I' ||
str[i] == 'O' || str[i] == 'U' || str[i] == 'a' ||
str[i] == 'e' || str[i] == 'i' || str[i] == 'o' ||
str[i] == 'u') {
count++;//count vowels
}
i++;
}
return count;
}
int main()
{
int n;
char str[100];
printf("Enter a string for count vowels: ");
scanf ("%[^\n]s", str); //take input a string from user
n = countvowel(str); //Call the function to count vowels
printf("\n No. of vowels are : %d", n);
return 0;
}
gets() is deprecated
you can use scanf to read space separated strings
What is wrong with this computer science program? I have an error at line 22, saying...
I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...
Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){ char str[1000], ch; int i, frequency = 0; clock_t t; struct timespec ts, ts2; printf("Enter a string: "); gets(str); int len = strlen(str); printf("Enter a character...
I need help fixing this code in C. It keeps giving me an error saying error: ‘O_RDWD’ undeclared (first use in this function) if ((fd = open(fifo, O_RDWD)) < 0) note: each undeclared identifier is reported only once for each function it appears in. Please fix so it compiles properly. //************************************************************************************************************************************************** #include <fcntl.h> #include <stdio.h> #include <errno.h> #include<stdlib.h> #include <string.h> #include<unistd.h> #include <sys/stat.h> #include <sys/types.h> #define MSGSIZE 63 char *fifo = "fifo"; int main(int argc, char **argv){ int fd;...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...
#include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() { char string[100]; char inputChoice, choice[2]; int vowelTotal, consonantTotal; //Input a string cout << "Enter a string: " << endl; cin.getline(string, 100); do { //Displays the Menu cout << " (A) Count the number of vowels in the string"<<endl; cout << " (B) Count...
#include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() { char string[100]; char inputChoice, choice[2]; int vowelTotal, consonantTotal; //Input a string cout << "Enter a string: " << endl; cin.getline(string, 100); do { //Displays the Menu cout << " (A) Count the number of vowels in the string"<<endl; cout << " (B) Count...
// Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...
You have to clearly define what each if statement is doing in both programs. #include <stdio.h> static unsigned char count = 31; void callMe ( char ch ) { if ( ch == 'U' || ch == 'u') { if ( count > 15 ) count -= 16; printf ( "count = %d \n", count ) ; return; } if ( ch == 'A' || ch == 'a') { if ( count % 2 == 1) count -= 1; printf...
The following code is a C Program that is written for encrypting
and decrypting a string. provide a full explanation of the working
flow of the program.
#include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...
i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...