C :: Printf In A While Loop Is Printing Twice Instead Of Once
Sep 21, 2013
I have a minor issue in my program:
Code:
char Answer;
printf("
To search for a specifc word, type (Y), to use a dictionary file, type (N):
[Code] .....
When I run the program, it gives:
To search for a specific word, type (Y), to use a dictionary file, type (N):
Sorry, the given input is invalid, please try again:
I can then input the number. Typing n,N,y or Y goes to the next part of the program without any problems, but if I type something else, I get:
Sorry, the given input is invalid, please try again:
Sorry, the given input is invalid, please try again:
I've fiddled about with the code for a while now, but nothing I do seems to work. What is causing it to be printed twice, or why the first getchar() is ignored.
View 2 Replies
ADVERTISEMENT
Jul 17, 2013
I am having trouble with the printf in this function:
Code:
void print_orig_array(char string_array[MAX_PEOPLE][NAME_SIZE], int ages[MAX_PEOPLE], int length) {
int counter;
printf("Original list");
printf("
[URL] ....
Here is the output:
Am I missing something with the format specifier? How do I fix the 84 that gets pushed out?
View 2 Replies
View Related
Jul 1, 2012
I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.
#include <stdio.h>
//Use to test ideas and formats//
main() {
int c, nc;
nc = 0;
[code]....
My result as compiled by gcc -o testing testing.c
This prints.
test
t1,e2,s3,t4,
5,
I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.
View 7 Replies
View Related
Jan 25, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 15
[Code]....
I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words
View 4 Replies
View Related
Jan 30, 2013
I am having a hard time with some of my homework, specifically regarding how to printf floats. I can't seem to print the number i want out using float, it just becomes a jumbled mess.
Code:
#include <stdio.h>
#define TICKER "LRCX"
#define PURCHASE_DATE "01/02/13"
#define SELL_DATE "01/30/13"
#define INVESTMENT_AMOUNT "10,000.00"
[Code] .....
Thats the code I currently have, I've probably tried everything to get the number to come out, but I just cant seem to figure it out. It should look like this, but with different numbers and stock:
Stock: MCD Buy Date: 01/02/13 Sell Date: 01/29/13 Buy Share Price: $89.40 Sell Share Price: $91.50 Shares Purchased: 111.86
Amount of Investment: $10,000.00 Value of Shares Sold: $10,234.90 Amount of Gain/Loss: $234.90 Percent Gain/Loss: 2.35%
However, this is how mine turns out:
Code::Blocks
Enter share purchase price for LRCX=>23
Enter the selling price for LRCX=>23
Stock: LRCX
Buy Date: 01/02/13
Sell Date: 01/30/13
Buy Share Price: -1.#R
Sell Share Price: -1.#R
Shares Purchased: -1.#R
Amount of Investment: 10,000.00
Value of Shares Sold:-1.#R
Amount of Gain/Loss:-1.#R
Percent Gain/Loss:-1.#R%
Process returned 0 (0x0) execution time : 2.864 s
Press any key to continue.
View 3 Replies
View Related
Apr 22, 2014
Code:
#include <stdio.h>
struct database {
int id_number;
int age;
float salary;
[Code] ....
When I compile, I get an error:
test.c|18|error: incompatible type for argument 1 of 'printf'|
note: expected 'const char *' but argument is of type 'float'|
I thought employee.salary is a float but the compiler expected 'const char'. How do I make this work?
View 4 Replies
View Related
May 6, 2013
I have the following line of the code. Now I want to save the content to a string. Is there a quick way for me to do the conversion using the same arguments/codes of printf?
printf ("Some different radixes: %d %x %o %#x %#o
", 100, 100, 100, 100, 100);
View 3 Replies
View Related
Sep 5, 2014
#include<stdio.h>
void main()
{
int i=6;
printf("%d %*d
",i,i+9);
}
what is the out put?
View 2 Replies
View Related
Feb 26, 2013
I'm making my way through most of this assignment that I have, but now it seems like I've run into a bit of a roadblock. The issue that I'm having is not being able to printf a series of ints that I thought I had previously defined in another function. I don't want to clog up this post with the entire code, so I'll just post one function that defined an int to give an example. I will upload the whole thing upon request however.
Code:
#include <stdio.h>
#include <stdlib.h>
//Prototypes
int AGrade1(int* grade1);
int AGrade2(int* grade2);
int AGrade3(int* grade3);
[Code] .....
I've tried many many things, but I just cant figure it out. This is what it's supposed to look like.
Assignment Grades:
18 12 17 15 20 13
20 18
View 9 Replies
View Related
Oct 6, 2014
I just checking but confused with float. in that code same size int, and same type double are working but float showing nothing in printf..why?? i'm using GCC compiler int 32bit win7 os
Code:
#include <stdio.h>
int main() {
char arr[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
printf("Size of char=%c
", ((char *) (&arr[0]))[1]);
[Code] ....
View 14 Replies
View Related
Jul 23, 2014
The overall width of the line is 20 characters. How can I center a string using print so that
title becomes
space-title-space
i have something like this so far Code: fprintf(myfile, "%20s ",mystring);
View 2 Replies
View Related
Oct 28, 2014
How to store the value in this case.. The topic is called "limited summation".. The following is the guideline for this problem:
Write a program in a folder called "sum" with a source file of main.cpp that does the following:
•prompt a user to enter a maximum number of entries, make the prompt "max # entries"
•prompt a user to enter a threshold sum, make the prompt "threshold"
•using error checking logic, let a user enter base-10 signed numbers until at least one of the following conditions is true:
or the maximum number of entries is reached
or the sum of entered numbers has reached (>=) the threshold
•print the sum of all the entries, just the number and a linefeed at the end of the line
Error checking means entries that are not numbers are detected and ignored. You are to use printf and scanf in this assignment (no cin or cout).
View 3 Replies
View Related
May 23, 2013
This code runs. However, when I run it, the text from printf doesn't appear until after I type in the two numbers.
I use Wascana, will it run correctly on other compilers?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
fflush(stdout);
[Code].....
And this is how it turns out on the screen:
Code:
6
3
What size is the die:
how many dice to roll:
Numbers are 3d6
Rolling die no.1...
RolledDie: 4 DieTotal: 4
Rolling die no.2...
RolledDie: 5 DieTotal: 9
Rolling die no.3...
RolledDie: 5 DieTotal: 14
The total is: 14
View 4 Replies
View Related
Apr 20, 2013
Okay so I am programming an 8051 variant to interact with an SD card. In a separate initialization routine in SD_CARD.c I pull out the vital information of the card into global variables. I then call Menu() which is in another source file but includes a header file with all of the variables declared as extern. Now here is the weird, part this is from my Menu.c
printf("%u" , VOLUME_1_SECTOR);
if(VOLUME_1_SECTOR==16384)
printf("Correct");
else
printf("Incorrect");
Now the output of the first printf is 16384 but the conditional evaluates to false. If I put this code in SD_CARD.c (Where VOLUME_1_SECTOR is defined) the conditional evaluates to true. I am confused why the printf works correctly in Menu.c but not the conditional.
View 2 Replies
View Related
Oct 12, 2013
I am trying to compare 2 strings of characters The users input containing 5 chars is compared to a table If the input is already be existent in the table the index of those chars in the table is printed Quest: how to copy the result of a printf() into an array ? The last printf() gives a sequence of numbers and I am trying to save that sequence to another array for further operation ! I have not been able to do that so far even with tmp[]=i ;
Code:
#include <stdio.h>
#include <string.h>
#define N 30
#define n 100
int main (void)
[code]....
View 2 Replies
View Related
Nov 10, 2014
I'm trying to create a program that will show what the 12th digit of a UPC code would be. However, once the user enters the first 11 digits the program doesn't execute the last call of printf. The program compiles with no issues.
Code:
#include<stdio.h>
int main() {
int o1, e2, o3, e4, o5, e6, o7, e8, o9, e10, o11, oddsum, evensum, twelve;
printf
[Code] .....
View 9 Replies
View Related
Apr 18, 2014
I cannot get the following to compile. The problem is the printf on the last line. I understand that printf requires a char (or pointer to char). I understand that I can convert between datatypes by putting the target data type in parenthises in front of the variable. But how do I cast the integer into a character and then get it's pointer to pass into printf?
Following is my code. I compile with gcc temp.c -o temp.
Note that I have tried many attempts at that last line and this is just the one that I really, really think should work (or is at least the closest to the correct answer).
This code shown below, using printf("%s", &(char)nextChar); returns
temp.c:26: error: lvalue required as unary '&' operand
If I try to use printf("%s", *(char)nextChar); I get the error
temp.c:26: error: invalid type argument of 'unary *' (have 'int')
This line printf("%s", (char)nextChar); returns the obvious
format '%s' expects type 'char *', but argument 2 has type 'int'
Code:
#include <stdio.h>
int main() {
printf("hello, world
");
#if defined(SUNDIALS_EXTENDED_PRECISION)
[Code] ....
View 5 Replies
View Related
Feb 13, 2013
I have gotten it to record the date and I can printf it either on the same function, or in the main(). However, one of the requirements I must adhere to is to printf the statement in a brand new function, but when I do that, it just doesn't work. Heres what I mean:
Code:
#include <stdio.h>
#define TICKER "LRCX"
#define INVESTMENT_AMOUNT "10,000.00"
//Prototypes
int getdate(int* month1,int* day1,int* year1,int* month2,int* day2,int* year2);
float getprice(float* BPrice, float* SPrice);
void printdate(int month1, int day1, int year1);
}
[code]....
View 3 Replies
View Related
Apr 19, 2013
I am currently debugging this function. I am trying to make this function's width specifier align like a printf() routine. Here 's the code:
v Code:
oid
bu_log(const char *fmt, ...) {
va_list ap;
struct bu_vls output = BU_VLS_INIT_ZERO;
if (UNLIKELY(!fmt || strlen(fmt) == 0)) {
bu_vls_free(&output);
[Code] ....
View 8 Replies
View Related
Oct 17, 2014
I have "hello world" set for command line args.
int main(int argc, char **argv) {
printf("%s %s", argv[1],argv[2]);
}
That code produces
w
r
d
Why would it do that.
View 2 Replies
View Related
Jan 14, 2015
I am currently trying to printf several values of a struct pointer but with little success.
#include"Header.h"
/*
In header:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct FileStruct {
char FileQuestion[64];
[Code] ....
As you can see I am trying to re-crate the output from the first loop in my second loop, however it is with little success. The second loop's first run re-crates the last output of the first loop and if I use FileStructPointer++ or -- the output goes broke.
See attached for how it looks in the console window.
Attached image(s)
View 3 Replies
View Related
Jun 26, 2013
how to print the result on screen without using printf in C...?
View 6 Replies
View Related
Jul 17, 2012
I am using print/sprintf with a "%i" format string. Works fine if the input is indeed a 32bit integer. But how can i put in 8/16 bit (ie short & byte) 'integers'? If i just throw them in, they are always taken as unsigned, as the topmost bit/s is/are casted to zero... [URL] ....
View 3 Replies
View Related
Feb 23, 2014
I can't seem to make this printf line work
printf("THE NUMBER PI
To six decimal places, pi is equal to \%f" ,3.141593 " which is roughly \%i", 3 "
");
I'm not sure what the correct syntax is to start and end a new write.
View 3 Replies
View Related
Sep 1, 2014
is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?
for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c
", m, ' ',*);
}
this is suppose to output
t=-3 *
t=-2 *
t=-1
.
.
.
This is supposed to output t=m and then m is plugged into a function say for -3, plugging it into function f gives 23, well i want 22 blank spaces and then a asterik and go to next line. that is why i put -1 after %'f(m)-1's i
The asterisk appear right next to the t value here but they are way to the right of it when i made this post.
View 2 Replies
View Related
Dec 2, 2013
I'm trying to get this programme to work but I can't get it to output the string data at the end of the line.I have copied and pasted the line in question below but it may be a prob with the prog further down.
It reads character input ok but doesn't put one string into another or recognize when a string is quoted in a printf.
Code:
printf("%s what is your second name?
", surname, name2, name);
#include <stdio.h>
int main ()
{
char name[20];
[Code] ....
View 8 Replies
View Related