C/C++ :: How To Print Results On Screen Without Using Printf
Jun 26, 2013how to print the result on screen without using printf in C...?
View 6 Replieshow to print the result on screen without using printf in C...?
View 6 RepliesThis 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
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.
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.
Here is the code:
int unsigned long a,b;
scanf("%lu",&a);
scanf("%lu",&b);
printf("%lu",a*b);
suppose we input a very large number on a and b (no more than 1000 digit)
like a = 1234567890123456789012345678901234567890
and b = 9876543210987654321098765432109876543210
it outputs 1, why is it?
It is probably the answer is too big, is there any way to show a*b?
So i am struggling for days to get this done and all i need is to get the sum of the areas and get them printed on the screen my code is this:
Code:
#include<stdio.h>
#include <stdlib.h>
#include<conio.h> //Not needed in Dev C++//
#define PI 3.1415
float Area_of_Rectangular(float length,float width);
float Area_of_Circle(float radius);
int main()
[Code]...
Print the inverse number. Ex: 2178*4=8712
Write down a program which can satisfy the prerequisite and print out the screen.
The answer is:
Code:
void inverse2 ()
{
int i,j;
for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)
if (i*j==inverse (i))
printf("%5d%2d",i,j);
}
I can't understand the double for loop.
for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)
And The meaning for
i*j==inverse (i)
How to print to the screen the value of n after it has been multiplied.
For example: if I use cout << "n: " << n << " power: " << power << "
"; I
can see the variable "power" decrementing by 1, but I don't see the variable "n" incrementing with its new value after it has been multiplied by n * n.
#include <iostream>
using namespace std;
typedef unsigned short int USHORT;
typedef unsigned long int ULONG;
ULONG Getpower(USHORT n, USHORT power);
[Code] .....
My objective is to check to see if a number is odd or even and print it to the screen just to make sure its working correctly.
The data file contains:
138
402 2 485
9
43
98 805
58
421
948 7 97
48
67
35
42
948
579 39 12
700 20 500 210
98
I can get the numbers to print fine using:
fstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else {
char listNum;
while(infile1.get(listNum))
cout << listNum;
}
However, when I check for odd or even numbers it will check each and every number.
printed like this (partial list):
1 is odd 3 is odd 8 is even
9 is odd
But it should print:
138 is even
9 is odd
I tried using getline, but it keeps giving me the errors:
invalid conversion from 'void*' to 'char**'
invalid conversion from 'char' to 'size_t*'
too few arguments to function 'ssize_t getline(char**, size_t*, FILE*)'
Here is the getline code, what am I doing wrong? I have tried switching things around, adding things. Just nothing works.
ifstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else {
char listNum;
getline(infile1, listNum);
cout << listNum;
}
Given this sentence as an input: "Hello my name and "John" (with its spaces and capital letters), print it on the screen .. NB the phrase must be entered from the keyboard all at once ... you can do this in C / C + +?
View 3 Replies View RelatedHow can I make the output print out to the screen in reverse?
Code: #include <iostream>
#include <iomanip>
using namespace std;
int getnum();
void Fibonacci(int n);
[Code].....
I'm trying to write a program that prints all of the prime numbers to the screen. I'm getting angry because it only prints EVERY number. I think it has something to do with the bool change not being able to leave the for-loop but how to fix it.
Code:
#import <stdio.h>
#include <stdbool.h>
int main(void){
printf("
The Primes Are: 1");
[Code] ....
is there anyway to read an entire file and print in on screen? file consists of strings and integers!
View 7 Replies View RelatedHow do I print a mathematical series such as
1 + 2/2! - 3/3! + ...... n/n! //n is read from user
Not only we need to print the series on the screen but at the same time find the sum using simple loops.
i am programming Cli/Ser ,so part of the program is to open file to download it from client side,but i want to return the global value Errorno to print it to screen , and how to use strerror() func ??? i write this "This is part of server code" :
Code:
fd= open("abc.txt",O_RDONLY);
//error handilng in open file
if(fd<0)
{
[Code].....
Why this program won't correctly print the proper totals on screen? See my code and the included screenshot.
Code:
#include <stdio.h>
int main(void) {
int total, first, second;
printf("Enter 2 numbers:
[Code] .....
This seems simple enough but I'm missing something here to make this code work.What I'm trying to do is print the contents of the two dimensional array in 25 rows and 4 columns. I experimented with something similar to this code when I initialized the array with numbers.
#include <iostream>
#include <iomanip>
#include <cmath>
[Code].....
I'm getting garbage. I tried including the name of the array in the cin object but I got an error message that says "no match for operator '>>'. When I take the name of the array out, the program compiles but I get garbage. Program is suppose to reads data from a file of 25 students and calculates test scores and class grade average output each student's name score, letter grade and grade average. I would be happy at this point if I could just print out something that wasn't garbage.
Here is the code.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
using namespace std;
//const
const int Array_Row = 25;
const int Array_Col = 4;
[Code] ......
I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include <vector>
using namespace std;
int main(){
vector <string> words;
string str, paieska;
[Code] .....
How to print line(s) where I found that word?
I am trying to automatically(periodically) print screen a custom area of the screen, save it as an image file (the image will have the same format always), and then use OCR to get the text in the image as usable string variables. Is this doable? I was looking into tesseract OCR but I find it a bit unclear.
View 10 Replies View RelatedI am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.
For example, if the number is 2339 the program should print
9 *********
3 ***
3 ***
2 **
So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!
My code so far:
int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d
[Code]...
I must take an old MFC project in VC++ 6.0 and make changes.
The problem is text size in screen is different from size in print preview.
for example with this font
Code:
CFont f50;
f50.CreateFont(100,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Frutiger LT Std 45 Light");
And this text
Code:
s=_T("Let's try to calculate the size of this text");
and with MM_LOMETRIC map mode
GetTextExtent() returns me:
On screen: (1595,99)
Ink printer + print preview: (1589,100)
PDFCreator + print preview: (1580,100)
comparing with screen size the height is bigger but lenght is smaller. I don't understand.
I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.
What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?
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.
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?
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);