|
Please explain how these code run for each line #include<stdio.h> /** /** /** /**
|
#include<stdio.h>
#include<string.h>
/**
* Part A
*/
/* Creating a Structure named myWord
* which holds word and the corresponding word length
*/
struct myWord{
//This will hold the word
char Word[21];
//This will hold the word length
int Length;
};
//Function declarations
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()
{
//Creating a Struct Array of size 20
struct myWord wordList[20];
//This will hold the user entered input sentence
char line[100];
//Getting the input sentence entered by the user
printf("Enter an English Sentence:\n");
gets(line);
//calling the function by passing the user entered input sentence
and struct array
int size = tokenizeLine(line, wordList);
printf("\n");
//Displaying the output
printf("Unsorted word list.\n");
//calling the function (so this will display contents of struct
array before sort)
printList(wordList, size);
//Calling the function to sort the struct array instances based on
the contents of word length
sortList(wordList, size);
printf("\n");
printf("Sorted word list\n");
//calling the function (so this will display contents of struct
array after sort)
printList(wordList, size);
}
/**
* Part B
*
* Function to tokenize the entered line and store each word and its
size
* in struct object variables.
*/
int tokenizeLine(char line[], struct myWord wordList[])
{
// Parsing the sentence when ever space , full stop ,
question mark or Esclamation character occurs
char *token = strtok(line, " .?!");
int indx = 0;
//This while loop will continue to execute until the end of the
line
while(token != NULL)
{
//We called the each parsed word from sentence
as Token , and store that token in struct word
strcpy(wordList[indx].Word, token);
//We store the length of the corresponding parsed word in struct
length
wordList[indx].Length = strlen(token);
//Again getting the next word from the sentence
token = strtok(NULL, " .?!");
indx++;
}
return indx;
}
/**
* Part B
* This function will print the contents of the struct array
*/
void printList(struct myWord wordList[], int size)
{
int i;
//This for loop will display all the contents of the struct
array (words and its length)
for(i = 0; i < size; i++)
{
printf("%s: %d\n", wordList[i].Word, wordList[i].Length);
}
}
/**
* Part C
*
* Function to sort the list based on the length of the words
* using bubble sort
*/
void sortList(struct myWord wordList[], int size)
{
int i, j;
for(i = 0; i < size-1; i++)
{
for(j = 0; j < (size - i - 1); j++)
{
if(wordList[j].Length > wordList[j+1].Length)
{
struct myWord temp = wordList[j];
wordList[j] = wordList[j+1];
wordList[j+1] = temp;
}
}
}
}
______________________________
Output:

________________________Thank You
Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...
#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)...
Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list...
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,...
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];...
#include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...
C Programming // Compile with: clang radio.c -o radio // Run with: ./radio #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size; song++){ // Allocate memory for each individual character string database[song] =...
#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] !=...
Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...
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...
Rewrite this code in Java please #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; long length = 1000; const long max_length = 100000; int list[max_length]; void read() { ifstream fin("random.dat", ios::binary); for (long i = 0; i < length; i++) { fin.read((char*)&list[i], sizeof(int)); } fin.close(); } void bubbleSort() { int temp; for(long i = 0; i < length; i++) { for(long j = 0; j< length-i-1; j++)...