Simplify for loop condition in getline.
This program reads lines from the terminal, converts them to C strings by appending \0, and prints the longest one found. We need the ability to read in a line and the ability to save a line. We write two function getline and copy for these task.
Using C language
![#include <stdio.h> #def i ne MAXL INE 1 000 int getL ine(char ne], int maxl ine); void copy( char to[], char from]); int main) int len, max; char Tine[MAXL INE], longest [MAXL INE] max0; whi le ((len getL ine(ine, MAXLINE))>0) if (len > max) max = len; copy (longest,line) if (max>0) printf(%s, longest); return 0; int getL ine(char s[], int lim) int c, i; for (i-0; i<lim-1 && (c=getchar()) !=EOF && s[i] = c; if (c=th) { return i; void copy( char to[], char from]) int i; i=0 ; while ((to[i] = from[i]) !-WO)](http://img.homeworklib.com/questions/216b5f50-0e6b-11ec-81eb-6d9dfff570bd.png?x-oss-process=image/resize,w_560)
It can't be simplify. In that loop, 3 conditions,
1) length condition
2) checking end of file(Ctrl+D)
3) checking for end of line
This 3 conditions are mandatory. we can't simply that conditions.
Let me know if you have any clarifications. Thank you...
Simplify for loop condition in getline. This program reads lines from the terminal, converts them to...
Create a UNIX makefile for the following C
program:
//convert.c
char toUpper(char c){
if(c>='a' && c<='z')
return c-32;
return c;
}
//converting sentance to upper
void convertSentence(char *sentence){
int i=0;
while(sentence[i]!='\0'){
//convert to upper for each character
sentence[i] = toUpper(sentence[i]);
i++;
}
}
//converting all sentences into uppercase
void convertAll(char **sentenceList, int numOfSentences){
int i=0;
while(i<numOfSentences){
//calling convertsentence function to conver uppercase
convertSentence(sentenceList[i]);
i++;
}
}
sentences.c
#include<stdio.h>
#include<stdlib.h>
#include "convert.c"
int main(){
//declaring character array
char **mySentences;
int noOfSentences;...
Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wunzip: file1 [file2 ...]\n"); return 1; } else{ for(int i =1; i< argc;i++){ int num=-1; int numout=-1; int c; int c1; FILE* file = fopen(argv[i],"rb"); if(file == NULL){ printf("Cannot Open File\n"); return 1; } else{ while(numout != 0){ numout = fread(&num, sizeof(int), 1, file); c...
This code in C converts infix to postfix and evaluates it. The problem is that it only evaluates one digit expressions. I need to fix it so that it can evaluate 2 digits expressions as well. #include <stdio.h> #include <ctype.h> #include <string.h> #include <math.h> #define SIZE 100 char s[SIZE]; int top=-1; void infixToPostfix(char *infix, char *postfix); void postfixEvaluation(char *postfix); void push(char elem){ s[++top]=elem; } char pop(){ return(s[top--]); } int pr(char elem){ // Order of precedence switch (elem) { case '(':...
The program is done in C. This program opens a file containing binary or text and reads every byte in the file and writes both the ASCII hex value for that byte as well as it’s printable (human-readable) character (characters, digits, symbols) to standard output. The issue I am having is when the file has multiple lines being read. The first line is read and done properly but the other lines do not work correctly. For instance, the text file...
Here is the (A3b-smallgrades.txt) text file:
Here is the (A3b-largegrades.txt) text file:
Here is the Program A3a without modification:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char
students[COLS][20]);
void printGrades(int ROWS, int COLS, int
grades[ROWS][COLS]);
void getStudents(int COLS, char students[COLS][20]);
void printStudents(int COLS, char students[COLS][20]);
void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char
Fgrades[]);
void printFinalGrades(int COLS, char Fgrades[]);
int main()
{
srand(time(0));
int stu = 0, assign = 0;...
This question has been asked before but the responses have been wrong. Please do not copy and paste their answers. Currently the program opens a file and reads every byte in the file and write both the ASCII hex value for that byte as well as it’s printable character to standard output with non-printable characters printing a "." Now, I want have an option where the program prints in binary instead of hex by typing "-b" at the command line....
My C program is supposed to make a random key the same length of
clear_text string and then use the random key to encrypt
clear_text, but I can’t get it to work.
A wΝΗ 1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 char* make_rand_key(int length, char* key); 5 void encrypt(); 7- int main() { 8 encrypt(); 9 } 10 char* make_rand_key(int length, char* key){ int range=78; int max=48; char c='a'; int i; 'srand(time(NULL)); for(i=0;i<length;i++){ C=rand()%range_max; key[i]=c; key[i]='\0'; return key; 23...
Question: For the picture writing question, if the question says that the picture length (height) and width are multiples of 5, then be prepared (for example) to handle a situation where you are being asked to blacken the fourth (vertical) strip from the left. Code: #include #include #include #include #define BUFFER_SIZE 70 #define TRUE 1 #define FALSE 0 int** img; int numRows; int numCols; int maxVal; FILE* fo1; void addtopixels(int** imgtemp, int value); void writeoutpic(char* fileName, int** imgtemp); int** readpic(char*...
Help me to fix this code in C language. This code converts infix expressions to postfix and then evaluate the expression. Right now, it works with single digits. I need to modify it so that it can evaluate expressions with also 2 digits, example: (60+82)%72. Additionally I need to display an error when the parenthesis don't match like (89+8(. I have muted some line that would print the postfix expression with a space like: 22 8 + when the input...
If you already answer this question, please skip, thanks C Programming. Fill in ... This program will be called with one command line argument that contains a string followed by an asterisk and an integer. Print out the string as many time as indicated by the integer. For example, when called as prog Hi*3, you print HiHiHi. Hint: Look for the '*' starting from the back of the string. len = strlen(arg) gives you the string length. When you have...