C :: How To Scan And Print Integer

Jan 28, 2013

This is my code:

int main() {
int num;
printf("Please enter a number: ");
scanf("%d", num);
printf("%d", num);
return 0;
}

when i compile and run it, it stops working and doesn't printf the integer.

View 3 Replies


ADVERTISEMENT

C/C++ :: Program To Scan Number And String Then Print Them To A File

Mar 19, 2015

I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :

1 test
2 dream
3 code

then output (in data.list file) would be:

1 test
2 dream
3 code
3 code

I also changed the program code so that it reads from data.list file. even here it duplicates last line!

so when program reads the info above saved in data.list it would be:

1 test
2 dream
3 code
3 code
3 code

here's the code for writing:

#include <stdio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;
fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist
while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X

[Code]...

and the one for reading from file:

#include <stdio.h>
#include <conio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;

[Code]...

How do I fix this behavior??

View 3 Replies View Related

C++ :: Shop Database - Take Customers ID And Scan Through A Text File Then Print Out Info

Apr 10, 2013

I have to create a small data base for a shop. One of the functions i am creating is taking a customers ID and scanning that through a text file and to print out the info about that customer. What i am having trouble with is where do i insert the string compare in my program?

//declaring array for input of customer ID
int customer_ID [20];
printf("Please enter the customer ID:");
gets( customer_ID ); //users input stored in the array

[Code] .....

View 2 Replies View Related

C++ :: Print Out Integers Between 2 And 256 That Are Integer Powers Of 2

Nov 5, 2013

Using a do-while loop, for loop, or while loop. This is what I have so far but i don't know what to do after that.

#include <iostream>
using namespace std;
int main() {
int num;
int min = 2;
int max = 256;
}

Also the results should be printed out with 10 integers per line, right justified in a 5 byte field.

View 1 Replies View Related

C++ :: How To Make A Program That Print Out Factors Of Integer

Oct 26, 2013

I want to make a simple program that will print out the factors of an integer. My program right now only outputs "The prime factors of 221 are 221, 221, 221, 221"... Where it should be "The prime factors of 221 are 1, 13, 17, 221"

#include <cstdio>
int factorsOf(int x);
//function
int main() {
int x = 221;
printf("The factors of 221 are ");

[Code]...

View 3 Replies View Related

C++ :: Separate Input Integer Into Its Individual Digits And Print

Apr 18, 2013

Write a full C++ program that inputs three-digit integer, separates the integer into its individual digits and prints the digits separated from one another. For example, if the user types 549, the program should print;

5 4 9

View 5 Replies View Related

C++ :: Receive Integer X And Print Alternating Alphabetic Characters

Feb 6, 2015

Q1. Recursive function that receives an integer x and prints the alternating alphabetic characters.

Write a main function to test the function;

ENTER NUMBER : 4

A C E G

Q2. Define a void function that finds the smallest value in the array and number of its occurrences. Also, it finds the largest value in the array and number of its occurrences.

ENTER 4 NUMBERS:
1 12 5 41 41

THE BIGGEST IS 41 AND IT OCCURS 2 TIME
THE SMALLEST IS 1 AND IT OCCURS 1 TIME

View 17 Replies View Related

C++ :: 3 Integer Numbers - Find And Print Mean / Maximum And Second Minimum

Oct 25, 2014

The question is: Write a program that reads 3 integer numbers, then finds and prints the: Mean - Maximum & Second Minimum.

#include <iostream>
using namespace std;
int main () {
double a, b, c;
cout<< "Please enter three values"<<endl;

[Code] .....

View 6 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

Visual C++ :: Pythagorean Triples - Read Integer N And Print

Sep 27, 2014

I need to create a code in c fits the description below,

Description : A positive integer triple (a, b, c) with 0 < a < b < c and a^2 + b^2 = c^2 is called a Pythagorean triple. Write a program in C which reads an integer N and prints

1. the total number of Pythagorean triples (a, b, c) with c < N,
2. every such Pythagorean triple, and
3. the triple that has the largest value of c.

Hint: you can enumerate all possible pairs (a, b) with 0 < a < b < N and check if they satisfy a

2+b
2 < N2
.

Example Input/Output

- Enter a positive integer: [3]
There is no Pythagorean triple in this range.

- Enter a positive integer: [15]
There are 3 Pythagorean triples in this range:
(3, 4, 5)
(5, 12, 13)
(6, 8, 10)
The triple with the largest value of c is (5, 12, 13).

- Enter a positive integer: [6]
There are 1 Pythagorean triples in this range:
(3, 4, 5)
The triple with the largest value of c is (3, 4, 5).

View 1 Replies View Related

C++ :: Read Unknown Number Of Integer Values And Then Print Count Sum And Average Of Odd Values

Apr 9, 2014

write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!

View 1 Replies View Related

C :: How To Get Scan Code Of ESC Key

Sep 17, 2014

i wrote the following code :

Code:

#include<stdio.h>#include<conio.h>
#include<stdlib.h>
int a[][4] = {15,9,10,25,6,2,4,7,32,19,42,8,21,17,18,0};
void boxes();
void display();
void main()
{int ch,r=3,c=3,t;

[Code]...

not able to esc when i press esc key.how to get rid of this.

View 4 Replies View Related

C :: Scan Value For Specific Data

Dec 13, 2014

I created a program that will create a file and print a list on it. Here is the code for my program:

Code:
int controlvalue(void) {FILE *controlvalue;
controlvalue = fopen("something.txt", "a+");
/* Series of fprintfs */
fclose (controlvalue);
return 1;}

Here is an example list created by my program:

Code:
[Gifts]Candy=45
Chocolate=32
Toy=128
Robot=754
Doll=1492
Star=21
Phone=72
Skateboard=87
Frame=314
Days=365
Perfume=421

I want to get the value of "Skateboard" on file. So I need to read 9 lines. On the 9th line, the gets() loop will stop. But, what if I only want to get the value of "Skateboard" as integer (87) and not a string? Also, is it possible to scan the value of Skateboard if it's located on a different (or unknown) line?

View 1 Replies View Related

C :: Multiple Entries Into Scan?

Sep 19, 2014

How would I be able to let the user enter multiple heart rates which would all be separate.

Code:

printf("Enter your recorded Heart Rates ");
scanf("%d", &in_rate);
//formulas
if (gender == 'm'){
target = 226 - age;
} else if (gender == 'f'){

[Code]...

View 1 Replies View Related

C/C++ :: Scan A Directory Recursively

Dec 19, 2014

I'm writing a C++ module that is meant to recursively scan a directory and I'm curious what yall think of my strategy.

The program is a music player and so I'm trying to make the directory scanner as lightweight and efficient as I can. I've decided I want to scan the files in two passes- first I just want to get a list of all music files that are found in a directory/subdirectories and then I want to process the list and search for id3s/other tags.

As I'm a scanning the directory, I've decided to store the temporary list in a linked list where each node is containing an array of 100 strings. I did this because I obviously don't know how long the list will be and I from my understanding of the C++ vector class it basically just makes over sized arrays and moves them when it runs out of space. That sounded rather clunky to me, as did a traditional linked list.. I didn't see the point of allocating memory that many times in a row.

View 3 Replies View Related

C :: How To Scan Text File And Put It Into Array

Mar 4, 2013

This is my text file.

bak kut teh[tab]888.0[tab]989.0
spicy chicken nugget[tab]999.0[tab]978.0

I'm experiencing some problem in trying to scan and put it into an array for the food names (e.g an array for food which consist of bak kut teh and spicy chicken nugget) and another 2 array for the other individual integer into C. However there seem to be some problem with my code.

Is there a difference if I use both tab and space instead of space for all?

Code:
#include<stdio.h>
int main() {
FILE *fp;
char food[100];
char buff[BUFSIZ];
float num;

[Code] ....

View 2 Replies View Related

C :: Using Fgets() To Scan A Data Before A Delimiter

Dec 21, 2014

Is it possible to fgets() the string (or word) only after a delimiter? I yes then how?

Example: Code: printer, scanner, machine

Also, how can I sscanf() a string with an indefinite number of sizes and assign it to only one variable?

Example:

Code:
str = "I Love C programming 9000";
sscanf(str, "%s %d", strvar, intvar);

View 13 Replies View Related

C++ :: Parallel Scan Of Sorted Sequences?

Feb 4, 2015

I need to take an unknown amount of sorted files and then output any number that is in at least half of them... I know I need to read in the files to a vector and then iterate through them all at the same time looking at the lowest number first and so on. But I am stuck at the point of taking an unknown amount of files and putting them in a container.

This is what I have so far but the vector isn't working and I think I should be putting each file into its own vector.

string get_file(string filename)
{
ifstream in(filename);
if (in)

[Code]....

View 3 Replies View Related

C :: How To Scan In Numbers From File And Find The Largest

Oct 4, 2013

I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.

input file text (first number is num of auctions, after that it's num of bids, then the bids):

5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23

Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!

The silent auction raised $2470.00 for charity!

Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>

[Code].....

View 4 Replies View Related

C :: How To Prompt User To Scan Numbers Into Array

May 17, 2013

i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:

Code:

float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);

The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.

how to scan numbers into an array so that they can be used for later use?

View 9 Replies View Related

C/C++ :: Scan Through One String To Find A Letter That Also Appears In Another?

Feb 3, 2015

I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:

char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}

but it continues to return wrong values idk what I'm doing wrong.

View 4 Replies View Related

C++ :: How To Scan Multiple Vectors For Common Elements Efficiently

Nov 6, 2013

we conform to the ISO C standard and this snippet of code : Code: vector<tree*> *leaves = new vector<tree*>[num_threads]; where num_threads is specified from command line arguments so not dynamically allocating it violates the standard.

Let's also assume num_threads is greater than one.

What I want to do is scan each vector in leaves for duplicates. If any two vectors in the set have matching addresses, they both immediately go onto the "unsafe" pile and will no longer be subject for testing.

If a vector clears one vector, we test it against the others in the set.

So if we have 3 vectors, A, B and C we test A against B then A against C. For efficiency, we then then just test B against C.

Like I said, I want a "safe" and "unsafe" pile. Every vector in "safe" is fully unique while every vector in "unsafe" is not unique.

I thought about just using a for-loop to loop through leaves and then iterate through each element but I'm not sure if that'll work just right out of the box.

View 14 Replies View Related

C++ :: Recursive Directory Scan - Can Use Multi-threading For Speed?

May 11, 2014

In our Qt application, we have to load several files on application start-up starting from a root directory.

We are recursively scanning the directories and loading the files.

The total time it takes is about 12 seconds. Can we reduce this time if we use multi-threading?

I have heard that multi-threading does not work everywhere and it increases code complexity and debugging issues.

Would multi-threading solve the above problem? We want it to be platform independent (Mac, Linux, Windows).

View 9 Replies View Related

C Sharp :: Scan Directory Selected From Treeview Control

Jan 20, 2015

I am doing "Virus Tracking System" Project. I have to scan the directory selected from treeview ....

View 9 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved