C :: Any Way To Read Entire File And Print It On Screen
Feb 26, 2013is there anyway to read an entire file and print in on screen? file consists of strings and integers!
View 7 Repliesis there anyway to read an entire file and print in on screen? file consists of strings and integers!
View 7 RepliesI am writing a program which compresses files into .zip files.
Here's my problem: Whenever I want to compress an executable file, my readFile function does not read the entire file. When I extract the .exe I get a very tiny and incomplete file.
Here's the function I use to read files:
std::string miniz_wrapper::readFile(FILE* f, int MAX_FILEBUFFER)
//MAX_FILEBUFFER has a default value of 65536 {
char* tmp;
std::string tmp_s;
int count = 0;
[Code] .....
Prior to reading, every file is opened using fopen with the mode "rb".
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 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 have a gridview in which I show report data, I wanted to print this data, so I added print functionality. This print functionality does not print entire gridview data, it only prints data which is visible on the screen and skip the data which is under vertical scroll bar.
Below is the print grid view code in c# for WINDOWS APPLICATION.
private void btnPrint_Click(object sender, EventArgs e)
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
[Code]....
How to open a file and just print what is in that file on the screen. I though maybe I had the directory wrong but putting G: or G: give me the same result. When I select 1 it just goes to the next line and doesn't print anything.
Code:
int getchoice(void)
{
int num;
int choice;
FILE* outputfile;
[Code] ....
I 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....
My professor wants me to write a program that will read from a dat file, and produce an output on the screen based on the file. I don't understand why I am getting this error. I suspect it has something to do with the number of characters I've told it to read.
#include<iostream>
#include<iomanip>
#include<fstream>
#include<assert.h>
#include<string>
using namespace std;
using namespace System;
struct TStudent {
string month[10];
[Code] .....
I noticed I had a 2 beside girl, after I removed it, it still didn't fix my problem.
Ok, I think I got the main idea of the I/O chapter. Though I think I might be oversimplifying the program because I am getting an interesting error.
Goal here is to read numbers from a file and print the numbers with totals for two of the columns and a calculated average for of the totals.
NOTE: The tables for the info from file look a lot better on my end. [QUOTE] seems to mess it up a bit from copying and pasting.
Info from problem:
Car No. Miles Driven Gallons Used
----------------------------------------------------
54 250 19
62 525 38
71 123 6
85 1,322 86
97 235 14
carinfo.txt file:
54 250 19
62 525 38
71 123 6
85 1322 86
97 235 14
program:
Code: updated code
Code:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
char buffer[256];
FILE * myfile;
myfile = fopen("read.txt","r");
[Code]...
I also got an error in printing wherein the data in read.txt is "Hello" newline "World" and my program prints world twice.
I know this is how you read from a file. I also want to print my output to the same name of the file plus ".txt". So if my file is called "text" I want to print it to a file called "text.txt".
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
[Code]....
Would it be something like this? Is it better to use "a" or "w" in the fopen? I want to write to it several times.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
[Code].....
I am having trouble in reading data from my text file and print it out exactly like how it looks like in the text file. The problem im having is it will not read the last y Coordinates of the point. it keep reading the second last point for y coordinates which is wrong.
my text file is
0.0 0.0
0.0 1.0
1.0 0.0(but it read until here)
0.0 0.0(suppose to read the last point which is here)
For your information, this is my 1st year degree assignment in C programming. It is to create a program which can read text file (manually create) and print it out in a program and calculate the area for the polygon using ADT function ( .c and .h files)
*This is the code for my read file function*
Basically this accepts a Polygon and a file pointer as parameters. It reads the polygon point data from the file, pass the read data to plg_new() to create a new Polygon and returns the new Polygon created.
Code:
polygon *plg_read(polygon *New_polygon, FILE *Coord) {
int i;
int numberofvertices=0;
int count=0;
char filename[50];
double xCoor[50], yCoor[50];
[Code]....
This is the second function my polygon new code. This ADT function basically creates a new Polygon with malloc(), initialize all ADT data members with its parameter values and returns the Polygon.
Code:
polygon *plg_new(double *xCoordinates, double *yCoordinates, int numberOfVertices) {
int x;
polygon *New_poly = (polygon *)malloc(sizeof (polygon));
if(New_poly->xCoordinates == NULL || New_poly->yCoordinates == NULL) {
free(New_poly);
[Code]....
This is the rest of the code if you need to refer to other codings.
Code:
/**
*@file polygon.c
*@brief Functions for polygon / Struct has polygon numberOfVertices, polygon *xCoordinates and polygon *yCoordinates
*@author: Tan Xian Yao
*@id: 4323440
*@date: 22/04/2014
*/
[Code]...
I have written the following code but i am stuck. Write a program that will prompt the user for a file name and open that file for reading. Print out all the information in the file, numbering each new line of text.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21], c;
int i = 1;
FILE *inFile;
[code]....
Objective of this program is to read binary data from a file and print it.
Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;
[Code] .....
But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!
I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.
I am in an "intro" C++ course and am having trouble with a section of my current project.
We are required to open a text file, read the data from that file, and print it back.
However, we are supposed to let the user input the name of the file that is to be opened. This is the code I have so far. It is not opening anything.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_QUESTIONS = 30;
typedef char CharArray[NUM_QUESTIONS];
string fileName;
[Code]...
I have been trying to read a comma separated .txt file into an array and print it to console in C++. The txt file consists of two columns of double type data. For some reason the program runs, but gives blank output in the console. I want to know if I am doing something wrong. So far this is what I have:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
int i=0;
double x[10];
double y[10];
string line;
[Code] .....
I am trying to read from a data file that has input as :
12.0, 11, 123
14.0, 12.1, 3
And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_INPUT 1000
int n =0;
int i = 0;
typedef struct {
double x[MAX_INPUT];
[Code] .....
The program when run gives the following output:
Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
ProjectB.c: In function "main":
ProjectB.c:59: error: incompatible type for argument 1 of "print_array"
1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food
2. Modify Food
3. Delete Food
4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.
Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88
The data may vary but it's always in this format.
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)
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
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 Related