C/C++ :: Read And Print A Char Array

Nov 25, 2014

In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.

I'm having an hard time to read a pixel map, or atleast ro print it on my main function.

I have a read_xpm function, which is given, therefore, working.

char *read_xpm(char *map[], int *wd, int *ht)

then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:

static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",

[Code]....

I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.

View 3 Replies


ADVERTISEMENT

C++ :: Read Comma Separated TXT File Into Array And Print It To Console

Oct 16, 2012

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] .....

View 3 Replies View Related

C++ :: Read Data From File Then Make It Into Array Of Structures And Print Afterwards

May 13, 2012

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"

View 1 Replies View Related

C/C++ :: Read Integers Into Array / Sort Numbers And Print Out Occurrence Of Each Number

Apr 6, 2014

My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.

void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */

[Code] .....

View 6 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies View Related

C++ :: How To Print Unsigned Char

Apr 23, 2013

How do I print an unsigned char in c++? E.g.

unsigned char a[100] = "acdef";
wprintf(L"a is %u
", a);
wcout << "a is " << a << endl;

gives

a is 2880488
a is 002BF3E8

and not

a is acdef
a is acdef

??

what is the difference between unsigned char and char?

View 6 Replies View Related

C :: How To Print The Max Number Row In Relation To The Char Arrays Row

Mar 30, 2013

I have most of the code working properly, but I'm having trouble with a certain area. Currently I have multiple 2D arrays. One is a char array and the other is an int array. In the int array I have to find the max number in each column, which I've done. The problem is, I need to print the max number's row in relation to the char array's row.

For example,

Code: int array[2][3] = {60 50 30 0 100 1}

The max numbers are 60, 100, 30.

char array[2][length+1] = {nameOne nameTwo}

How it needs to print:

nameOne has max score of 60.
nameTwo has max score of 100.
nameOne has max score of 30.

I just can't understand how to compare the two arrays in the right way, so it'll know that nameOne is associated with the numbers in row 0 and nameTwo in row 1, etc.

View 1 Replies View Related

C++ :: Print Linked List But As A Vector Of Char

Aug 26, 2013

I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:

char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list

[Code] ....

But when I print that, I get a bunch of weird symbols...

View 7 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C++ :: Program Compiles But Refuses To Print Out Char Grades?

Nov 10, 2014

#include <fstream>
#include <ostream>
#include <iostream>
#include <iomanip>

using namespace std;

const int NAMESIZE = 15;
const int MAXRECORDS = 50;

[Code] ....

View 2 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C :: Read And Print To File?

Jul 15, 2013

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

View 8 Replies View Related

C++ :: Read From Input And Print It Out

Jan 31, 2013

I am trying to read from this input and print it out to stdout:

#include <cstdio>
FILE* InputFile;
//struct CityBlock
//{
// bool Blocked;
// bool N_Blocked;
// bool FireStation;

[Code] .....

It outputs whole lot of nonsense snippet:
8?/usr/lib/libSystem.B.dylib&X)`!jH??H???H?H?u??????
H?H???H?H?9u?H??<????????UH??H??H?}?H?H???wH??]???
UH??H?? ?}?H?u??E???H??H???l?H??E???????H??H?????????
????M?M??u?H?gH????E??E?E?E?H?? ]ÐUH??????lj??

View 4 Replies View Related

C++ :: Function To Read HEX And Print ASCII?

Apr 20, 2014

is there a function or something that take HEX and print it's corresponding ASCII Character ..

Here is my Code to take Character Array [4] and Print it's HEX to File ..

but i don't know how to reverse ! ?

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(){
char buffer[4];

[Code] .....

View 1 Replies View Related

C :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 Replies View Related

C :: Any Way To Read Entire File And Print It On Screen

Feb 26, 2013

is there anyway to read an entire file and print in on screen? file consists of strings and integers!

View 7 Replies View Related

C :: Unable To Read Data From Text File And Print It

May 12, 2014

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]...

View 6 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

Visual C++ :: Read A File Which Is 51563 Char Long?

Nov 15, 2014

I'm trying to read a file which is 51563 char long ( a jpeg pic )

but whenever I open it :

Code:
std::ifstream ifs(file);
std::string pub((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
cout << pub;

I only get like 500 chars, so I tryed a lot of different funcs until I finally realized that they reached the end of file "early" well it thinks that one of the chars in it is an end of file and it's located at the start. So I really don't know what to do with it because every func doesn't see the rest of the file at all.

View 7 Replies View Related

C++ :: Read Text File - First Line Has Extra Char

May 21, 2012

When I read a text file. I'm reading a list of strings in text file, with one string per line. The first line has extra characters in the string, the rest of the lines read are fine, and I can't understand where the extra characters come from. The file format is this...

A
AA
AAN
AAP
AAPL
AAWW
AAXJ
....
...

Code:
std::vector<std::string> strSymbolList;
std::string s = "";
std::ifstream infile( m_strFileSymbols );
while( std::getline(infile, s) ) {
strSymbolList.push_back(s);
}
infile.close();

View 3 Replies View Related

C :: Read Txt File And Print Contents Numbering Each New Line Of Text?

Apr 25, 2013

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]....

View 3 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

Mar 14, 2013

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.

View 4 Replies View Related

C++ :: Program Read In 15 Integers From User Then Store And Print Out Numbers

Apr 29, 2014

I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.

View 7 Replies View Related

C++ :: Open A Text File Then Read Data And Print It Back?

Nov 5, 2013

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]...

View 2 Replies View Related

C++ :: Read List Of Numbers From A File And Then Print Out In Reverse Order

Apr 6, 2013

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.

View 2 Replies View Related







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