#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++;
}
str[i] = '\0';
}
return str;
}
int numUppltr(char *str)
{
int Upltr=0;
while(*str)
{
if(*str>='A' && *str<='Z')
{
Upltr++;
}
str++;
}
return Upltr;
}
int numLwrltr(char *str)
{
int lwrltr=0;
while(*str)
{
if(*str>='a' && *str<='z')
{
lwrltr++;
}
str++;
}
return lwrltr;
}
int punChar(char*str)
{
int count=0,i=0;
while(str[i])
{
if(ispunct(str[i]))
count++;
i++;
}
return count;
}
int numWords(char*str)
{
int wordcount=1,i=0;
while(str[i])
{
if(str[i]==' ')
++wordcount;
i++;
}
return wordcount;
}
int numDigit(char *str)
{
int digitcount=0;
while(*str)
{
if(*str>='0' && *str<='9')
{
digitcount++;
}
str++;
}
return digitcount;
}
Please I want to modify the above program Instead of reading data from the keyboard, get the data from a file. Ask the user for the filename.
The updated source code is given below:
#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];
FILE *fptr;
char fileName[100];
puts("Enter the file name: ");
gets(fileName);
//open file
fptr=fopen(fileName,"r");
int i = 0;
char ch=fgetc(fptr);
while(ch!=EOF)
{
givString[i++]=ch;
ch=fgetc(fptr);
}
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++;
}
str[i] = '\0';
}
return str;
}
int numUppltr(char *str)
{
int Upltr=0;
while(*str)
{
if(*str>='A' && *str<='Z')
{
Upltr++;
}
str++;
}
return Upltr;
}
int numLwrltr(char *str)
{
int lwrltr=0;
while(*str)
{
if(*str>='a' && *str<='z')
{
lwrltr++;
}
str++;
}
return lwrltr;
}
int punChar(char*str)
{
int count=0,i=0;
while(str[i])
{
if(ispunct(str[i]))
count++;
i++;
}
return count;
}
int numWords(char*str)
{
int wordcount=1,i=0;
while(str[i])
{
if(str[i]==' ')
++wordcount;
i++;
}
return wordcount;
}
int numDigit(char *str)
{
int digitcount=0;
while(*str)
{
if(*str>='0' && *str<='9')
{
digitcount++;
}
str++;
}
return digitcount;
}
INPUT
input.txt
hello
OUTPUT:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[], int *p_top, char value); char pop(char S[], int *p_top); void printCurrentStack(char S[], int *p_top); int validation(char infix[], char S[], int *p_top); char *infix2postfix(char infix[], char postfix[], char S[], int *p_top); int precedence(char symbol); int main() { // int choice; int top1=0; //top for S1 stack int top2=0; //top for S2 stack int *p_top1=&top1; int *p_top2=&top2; char infix[]="(2+3)*(4-3)"; //Stores infix string int n=strlen(infix); //length of...
#include <stdio.h> #include<string.h> int main() { char strText[100] ="Start"; char i; int nTextASCIISum = strText[0] + strText[1] + strText[2]; int nTextLen = strlen(strText); int count = 0; printf("Welcome to token generator!\n"); printf("Enter a word to use in the token generator.\n You may enter as many words as you like. \n Press q and key when finished.\n"); scanf("%c", &strText[i]); //compute when to stop loop //check nTextLen == 1 and strText[0] == 'q' for(i=0;i< nTextLen;i++) if ((strlen(strText) != 1) || (strText[0] !=...
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++;...
what is the output of the following program? #include<stdio.h> #include<string.h> int main(void){ char word[20]; int i =0 strcpy(word, "ORGANISE"); while(word[i] !='\0'){ if(i%2 ==1) word[i] = 'C'; i++; } printf("%s",word); return 0; }
What are the description of approach or technique used in this? #include <stdio.h> long charCount=0; long digitCount=0; long lineCount=0; long wordCount=0; long digitFreq[10]; int c=0; int outOfWord=0; int state=0; int inWord=1; void printStats(); void totalWords(); void totalLines(); void digitFrequency(); int main(int argc,char **argv) { int i; for(i=0;i<10;i++) { digitFreq[i]=0; } state=outOfWord; c=getchar(); while((c !=EOF)) { charCount++; digitFrequency(c); totalLines(c); totalWords(c); c=getchar(); } printStats(); return 1; } void totalLines(int c) { if(c == '\n') { lineCount++; } } void digitFrequency(int c) {...
Q4) what is the output after the code below is executed? #include <stdio.h> #1 nclude<string.h> int main) char abc[100]-"Good Luck in Your Programming Final" int i, ; while(abc[i]!= '\0'){ if(abc[i]' if(abc[i+1]-'&&abci+1] -'0' else printf"c", abcli-1]) printf("\n w = %d return 0; \n", w); Place you answer here 4 l Page
what's wrong with my code?????? #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXBINS 99 #define MAXCORS 26 #define MAXCUS 100 #define MAXPUR 10 /* datatype for a list of orders ----------------- */ typedef struct { int bin_order_number; char bin_order_char; }bin_order; typedef struct { int orderNo; bin_order orderbin; }order; typedef struct { int cusnumber; int n; /* number of the orders what the txt include */ order oo[MAXPUR+1]; }customer; typedef struct{ int n; /*number of the customers */ customer cc[MAXCUS+1];...
Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...
I NEED HELP FINDING THE BUG IN THIS CODE USING THE GDB #include #include <stdio.h> <string.h> Return the result of appending the characters in s2 to s1 Assumption: enough space has been allocated for sl to store the extra characters. char* append (char s1[ ], char s2[ ]) int sllenstrlen (s1); int s2lenstrlen (s2) int k; for (k=0; k<s21en; k++) { sl [kts11en] = s2 [k] ; return sl; int main () char strl [10]; char str2 [10]; while (1)...