Question

/* * This program reads characters from stdin and writes them back to stdout. * Student...

/*
* This program reads characters from stdin and writes them back to stdout.
* Student task: change code so that output is rotated output one position
* to the left. Thus, if input is "abcd", output should be "bcda".

#include <stdio.h>
#define BUFFER_SIZE 81

int main(int argc, char **argv) {
char string[BUFFER_SIZE];

while(fgets(string, BUFFER_SIZE, stdin) > 0) {
int numChars = 0;
while(string[numChars] && string[numChars] != '\n')
++numChars;

int i;
for(i = 0; i < numChars; ++i)
putchar(string[i]);

putchar('\n');
fflush(stdout);
}

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*
* This program reads characters from stdin and writes them back to stdout.
* Student task: change code so that output is rotated output one position
* to the left. Thus, if input is "abcd", output should be "bcda".
*/
#include <stdio.h>
#define BUFFER_SIZE 81

int main(int argc, char **argv) {
char string[BUFFER_SIZE];

while(fgets(string, BUFFER_SIZE, stdin) > 0) {
int numChars = 0;
while(string[numChars] && string[numChars] != '\n')
++numChars;

int i;
for(i = 1; i < numChars; ++i)
putchar(string[i]);
putchar(string[0]);
putchar('\n');
fflush(stdout);
}

return 0;
}
Add a comment
Know the answer?
Add Answer to:
/* * This program reads characters from stdin and writes them back to stdout. * Student...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert C to C++ I need these 4 C file code convert to C++. Please Convert...

    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...

  • The program reads an unknown number of words – strings that all 20 characters or less...

    The program reads an unknown number of words – strings that all 20 characters or less in length. It simply counts the number of words read. The end of input is signaled when the user enters control-d (end-of-file). Your program prints the number of words that the user entered. ****** How do you I make it stop when control-d is entered. My code: #include <stdio.h> void main(void) { char sentence[100]; int i = 0; int count = 1; printf("Enter a...

  • Below is a basic implementation of the Linux command "cat". This command is used to print...

    Below is a basic implementation of the Linux command "cat". This command is used to print the contents of a file on the console/terminal window. #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) {FILE *fp; if(2 != argc) {priritf ("Usage: cat <filename>\n"); exit(1);} if ((fp = fopen(argv[1], "r")) == NULL) {fprintf (stderr, "Can't. open input file %s\n", argv[1]); exit (1);} char buffer[256]; while (fgets(X, 256, fp) != NULL) fprintf(Y, "%s", buffer); fclose(Z); return 0;} Which one of the following...

  • Please help run all the examples correctly and only the examples without extra things in or...

    Please help run all the examples correctly and only the examples without extra things in or less things in, it should run EXACTLY 100% like the examples. C language ONLY. And please dont reply if you cant run all the examples given. We know the tr command allows you to replace or translate characters in of a stream. It takes in two arguments - a set of characters to be replaced and a set of replacement characters. The full functionality...

  • C Language Programming. Using the program below - When executing on the command line only this...

    C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...

  • need this in c programming and you can edit the code below. also give me screenshot...

    need this in c programming and you can edit the code below. also give me screenshot of the output #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define LINE_SIZE 1024 void my_error(char *s) { fprintf(stderr, "Error: %s\n", s); perror("errno"); exit(-1); } // This funciton prints lines (in a file) that contain string s. // assume all lines has at most (LINE_SIZE - 2) ASCII characters. // // Functions that may be called in this function: // fopen(), fclose(), fgets(), fputs(),...

  • Fill in the TODO parts of this skeleton to implement a miniature version of the GNU...

    Fill in the TODO parts of this skeleton to implement a miniature version of the GNU readline library. i.e. Store the characters in a malloc buffer as they come to you from stdio, and return the buffer. skeleton code is: #include <stdlib.h> #include <stdio.h> char *readline(const char *prompt) { fputs(prompt ? prompt : "> ", stdout); fflush(stdout); int c; // TODO: declare a char * while ((c=fgetc(stdin)) != EOF) { // TODO: store c inside char * on the heap...

  • In the Source Folder (src) of this project create a new C source file called "gcd.c"....

    In the Source Folder (src) of this project create a new C source file called "gcd.c". Once again, copy the contents of the "main.c" file above into the "gcd.c" source file. Modify this program to NOT ask the user to input the second Positive Integer, if the user has entered a program terminating value for the "first" input Postitive Integer. #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int...

  • // Write a program that determines how many of each type of vowel are in an...

    // 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...

  • 1. Suppose you wrote a program that reads data from cin. You are now required to...

    1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes. I. Declare an ifstream variable in_file II. Replace all occurrences of cin with in_file III. Replace all occurrences of > > and get_line with the appropriate operations for ifstream objects What changes do you need to make? I, II, and III II and III I and III...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT