How do you alter the following scanf statement in C?
I have the following line of code: scanf("%[^.]s)", string);
My problem is that this terminates the user input after the user enters a period, followed by Enter.
for ex: Enter a string: Today is nice.
How can I change this statement so that user would need to enter a new line, followed by a period and then press Enter so that the input would terminate?
for ex. Enter a string: Today is nice
.
Check out the solution and let me know if you have any queries through COMMENTS else THUMBS UP
_____
#include<stdio.h>
int main() {
char string[256];
//scanf("%[^.]s", string);
//printf("String which terminate with period : %s", string);
// string will stop with - newline .hence %[^ ]
// then string will stop with period - %[^.]
// then string terminate with newline or Enter key - %*[^ ]
// as this final Enter key should not be stored in string, '*' is used in above constraint.
scanf("%[^ ]%[^.]%*[^ ]", string);
printf("String which terminate with enter : %s", string);
}
__________
______
____
How do you alter the following scanf statement in C? I have the following line of...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...
Consider the following code.
while (!(productCode >= MIN_PRODUCT_CODE) || !(productCode <= MAX_PRODUCT_CODE)) {
System.out.println("!!! Invalid product code");
System.out.print("Enter product code:");
productCode = Integer.parseInt(input.nextLine());
}
My question is ... how you keep entering user until is valid?
When I entered any number that is invalid input, works fine. I keep entering input value. However, when I entered A , it terminates the program. How do I keep entering the user even if the inputs are String?
Enter product code: a Exception...
C PROGRAMMING Write a printf or scanf statement for each of the following: a) Print unsigned integer 2001 right justified in a 12-digit field with 6 digits. b) Print 3.150 in a 9-digit field with preceding zeros. // part of my answer: Printf(“%09 c) Read a time of the form hh-mm-ss, storing the parts of the time in the integer variables hour, minute and second. Skip the dash (-) in the input stream. Use the assignment suppression character. d)...
****Using C and only C****
I have some C code that has the function addRecord, to add a
record to a linked list of records. However, when I run it, the
program exits after asking the user to input the address. See
picture below:
Here is my code:
#include<stdio.h>
#include<stdlib.h>
struct record
{
int accountno;
char name[25];
char address[80];
struct record* next;
};
void addRecord(struct record* newRecord) //Function For Adding
Record at last in a SinglyLinkedList
{
struct record *current,*start,*temp;...
Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...
please use c programme Write a program which simulates a calculator using the following specifications. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • User input must have the following format - value1 operator value2 • Compute value1 operator value2 • Use switch statement • Operators must be ’+’ ,’-’, ’*’, ’/’ and ’%’ • Division by 0 in C leads to an error. Terminate the program before divison occurs in such cases. •...
Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write a program to ask the user for a number that includes a decimal point. Then display the integer part of the number (the part of the number to the left of the decimal point) and the decimal part of the number (the part of the number to the right of the decimal point, including the decimal point Follow the 3 steps in the Information...
Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...
Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...
Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...