#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] != 'q')){
printf("%c",strText[i]);
count ++;
printf("Current number of token entered %d\n", count);
printf("Current token value = %d\n", nTextLen);
printf("Current final token value = %d\n", nTextASCIISum); }
}
printf("Thank you for using tokengen!");
} //end function
I am having an issue with my program. It is not working quite the way I planned.
I am trying to get it to do this below:
Read a string and compute the summation of each character ASCII code
It will keep track of the sum of the characters for each word
Track the smallest and the largest token summation
Track the final token summation and number of token entered
#include <stdio.h>
#include<string.h>
int main()
{
//displaying message to user
printf("\n\tWelcome to token generator!\n");
printf("Enter a word to use the token generator.You
may enter as many words as you like.Press q and key when
finished.\n");
//array to store user entered string
char strText[100];
int i;
//count will count the number of words/tokens
entered
int count = 0;
//nTextASCIISum will sum up the character's ascii
values
int nTextASCIISum;
//nTextLen will find the length of the entered
word/token
int nTextLen;
//prompt user to enter a word
printf("\nEnter Word: ");
scanf("%s", &strText);
//loop will iterate till user enters q
while(strText[0] != 'q')
{
count ++;//word count
incremented
nTextLen=0;
nTextASCIISum=0;
//finding length of the word/token
and summing ascii values of characters
for(i=0;strText[i]!='\0';i++)
{
nTextASCIISum+=strText[i];//summing
nTextLen++; //finding length
}
//displaying
printf("\nNumber of token entered :
%d\n", count);//word count till now
printf("\nCurrent token length:
%d\n", nTextLen);//current token's length
printf("\nCurrent token value =
%d\n", nTextASCIISum); //current token's ascii value
//again prompt user to enter
another string
printf("\n\nEnter Word: ");
scanf("%s", &strText);
}
//at the end
printf("\n!.......Thank you for using
tokenGen.......!\n");
}
#include <stdio.h> #include<string.h> int main() { char strText[100] ="Start"; char i; int nTextASCIISum = strText[0] +...
#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)...
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; }
Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{ char Word[21]; int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() { struct myWord wordList[20]; char line[100]; printf("Enter an English Sentence:\n"); gets(line); int size = tokenizeLine(line, wordList); printf("\n"); printf("Unsorted word list.\n"); printList(wordList, size);...
#include <stdio.h> #include <string.h> #define WORDLEN 20 char smallest_word[WORDLEN + 1], largest_word[WORDLEN + 1], word[WORDLEN + 1]; void get_first_word(void); void get_another_word(void); void get_word(void); int main(void) { get_first_word(); while (strlen(word) != 4) get_another_word(); printf("\nSmallest word: %s\nLargest word: %s\n", smallest_word, largest_word); return 0; } void get_first_word(void) { get_word(); strcpy(smallest_word, word); strcpy(largest_word, word); } void get_word(void) { printf("Enter word: "); scanf("%20s", word); } void get_another_word(void) { get_word(); if (strcmp(word, smallest_word) < 0) strcpy(smallest_word, word); else if (strcmp(word, largest_word) > 0) strcpy(largest_word, word); }...
#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++; }...
can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf format dont worry about the answers i have down Q3, What is the output of the program shown below and explain why. #include #include <stdio.h> <string.h> int main(void) ( char str[ 39764 int N strlen(str) int nunj for (int i-0; i t Nǐ.de+ printf(") num (str[] 'e); I/ digits range in the ASCII code is 48-57 if (nue > e) f 9 printf( Xdin,...
#include <stdio.h> int main(int argc, char *argv[]) { int i; for (i = argc - 1; i > 0; i--) printf("%s ", argv[i]); printf("\n"); return 0; } can you explain this code in c and why use this function
C program help #include #include #include void PrintName(char firstname[16], char lastname[16]); int main () { char firstname[16]; char lastname[16]; printf("please enter your first name:"); scanf("%s",firstname); printf("please enter your last name:"); scanf("%s",lastname); PrintName(firstname,lastname); return 0; } void PrintName(char firstname[16], char lastname[16]){ char fullname[34]; *fullname=*firstname+*lastname; (char*) malloc (sizeof (*fullname)); if (strlen(firstname) > 16||strlen(lastname)>16||strlen(fullname)>16) fflush(stdin); else printf(" the full name is %s %s \n",firstname,lastname); printf(" the full name is-> %s",fullname);/*why is one not run*/ return 0; }
Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float average; int customerNumbers[num]; int customerSales[num]; printf("How many customers do you want to track?\n"); scanf("%d",&num); while(i<num) { printf("Enter the customer number. "); scanf("%d",&customerNumbers[i]); printf("Enter the sales for the customer "); scanf("%d",&customerSales[i]); i++; } printf("Sales for the Customer"); printf("\nCustomer Customer"); printf("\nNumber Sales"); for(i=0;i<num;i++) { printf("\n %d \t %d",customerNumbers[i], customerSales[i]); sum=sum+customerSales[i]; } average=(int)sum/num; printf("\n Total sales are $%d",sum); printf("\n Average sales are $%.2f",average); printf("\n --------------------------------------------");...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...