C/C++ :: Reading Hex Values From File And Printing Them In Decimal

Dec 1, 2013

I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.

I already read about strtol but I would prefer reading the hex Value into an integer.

Here is my code so far:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int itrack1[1];
int itrack2[1];

[Code] ....

View 11 Replies


ADVERTISEMENT

C/C++ :: Reading File And Printing Stuff

Jun 5, 2014

void readpatient() {
int count = 0;
f = fopen("patient.txt","r");
while(!feof(f)) {
printf("
%d",count++);
p2=new patient();

[Code] .....

Here is what I've tried. I'm trying to read a file aND print stuff in it, but my while loop isn't ending up.. What should i do? It only prints patient name 1 time and after that it prints nothing.

removing system("pause");

results in an endless loop.

View 2 Replies View Related

C/C++ :: Reading Strings From A Text File And Printing Them

Feb 26, 2015

I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

[Code].....

It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.

View 1 Replies View Related

C++ :: Banking System - Searching For And Printing Values From TXT File

Mar 21, 2013

So I'm doing a kind of banking system. Atm I've got the user able to create an account and set the balance of it, which is written to a .txt file. However, I would like the user to be able to enter their account no. and the program to cout the account info on the screen. I will be adding more to the program later, but until I work out how to search for values in a .txt file, and print out values on that line I'm a bit stuck.

Code:
Main.cpp -
#include <iostream>
#include "create_account.h"
#include <fstream>
using namespace std;
int menuin;
int main() {
create_account creataccObj;

[Code] .....

Sample .txt file -

// Account_no - Balance //

1001 140500
1002 150600
1003 18600

View 8 Replies View Related

C++ :: Reading File Then Printing Data Onto Other File

Nov 7, 2014

I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.

Example of the file being read

Code:
Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.

[Code] .....

View 14 Replies View Related

C++ :: Recursive Function - Printing Integer With Decimal Separators

Apr 7, 2013

I am trying to solve the following task:

-Write a recursive function that prints an integer with decimal separators. For example, 12345678 should be printed as 12,345,678.

The problem is that I don't know how to modify the integer in such way. I was thinking to convert it into a string, do an algorithm and then turn the string back to integer.

How to do such modification.

View 9 Replies View Related

C :: Reading Values From CSV File Into Array

Jan 21, 2014

My problem is that I need to take a csv or excel file with tens of thousands of datapoints, write all points in a section of column to an array, perform calculations on them, and then write it back into another column.

I've been looking all over the internet for ways to do this easily. So far I have not found anything that I can follow and implement.Some codes have been slightly useful, but they aren't commented in a way I can understand. How to write code to take, for instance, lines from column b between 500-1000, write them to an array, and write another array 500 characters in column c. If that code could be commented, I have tried a few different techniques (counting commas), but haven't gotten anything to work.

View 9 Replies View Related

C :: Reading Values From TXT File And It Hangs

Oct 5, 2013

I have a .txt with a 0 or 1 to each line of the txt file. there are many values to read. I am reading the values and calculating how many each reoccur in a sequence (run-length encode). If i only use say 50 values coming in it works, but once i do the hundreds there are in the file it hangs. i am not sure why.

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

FILE *infile;
FILE *outfile;

void PrintBinary(int x,int y);

[Code] ....

View 3 Replies View Related

C++ :: Program Is Not Reading In Values From DAT File Correctly

May 20, 2013

We are supposed to split this lab into 3 files a .h and 2 .cpp's. The code I'll be talking about is going to be directed at the main.cpp file. Basically we are supposed to be able to enter as many classes into the program and when you are done the program is supposed to save the contents into a .dat file. This lab is working off of an older lab so I already have a .dat file I am trying to test with this program by reading it into my program when I first run it I prompt if the user wants to load previously entered courses and if they reply with a 'Y' the program will load the contents of the .dat file. Problem is right now when I load from the .dat file only the first class is correct. Every other class after that is just giberish. I've tried everything but can't get the restore part working. I also cannot get the save to .dat portion of this lab working either.Here is my code:

#include "Course.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;

[code]....

View 1 Replies View Related

C++ :: Reading Data (Array Values) From TXT File

Mar 25, 2013

I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:

20 40 20 25 30
20 30 40 20 25
20 40 20 25 30
20 30 40 20 25
30 40 40 30 40

I am using getline, and then converting it to int by using atoi. But my code is not working.

Code :

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 5 Replies View Related

C++ :: Reading Values In Order In File And Assign?

Apr 12, 2014

My game is a sort of RPG with stats, money etc. I just recently added a save/load system using writing to a file. I initially got writing to a text file to work, then I got loading to work too.I eventually was able to read numbers from the file and assign them to integer variables in order.

My issue was I wanted to check if a save file existed, if it did, load it up, if it did not, go to character creation. I had a lot of trouble with this and after trying different code snippets to work I finally got it to check if a file existed, and execute the appropriate code.

My issue now is my code USED to go through each entry and assign variables in order.

Like the first number in the text file would be for the variable money, and it would read it, assign to to int money and scroll to down to the next variable for player strength, assign to to playerstr variable and so on. After making the tweak for loading it no longer functions like this, and makes the last entry in the text file the value for everything.

Here's my code:

Save Code:

{
ofstream savegame;
savegame.open("C:/Sounds/savegame.dat", ios::trunc);
savegame << money << endl;
savegame << playerstr <<endl;

[Code]....

I barely get how this code works, how can I tweak it to go through the file in order and assign variables one at a time?

At the current moment, it assigned the playerstr value to both money and playerstr int. But the save file being created lists the correct values in order.

View 5 Replies View Related

C++ :: Reading File Values By Passing Reference To A Function?

Oct 11, 2013

I am trying to read the file which has the values stored in the following pattern

2 4 10 103 2 504 .... and so on

I Have opened the file and then passed the opened file to another function to process it further.

here is my code

#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>

[Code].....

now the problem is when the control exits the "while loop" in the function "readingValues(std::ifstream& myFile)it goes straight to catch block ?

View 9 Replies View Related

Visual C++ :: Reading CSV File - Show Values In List?

Dec 26, 2012

I have problem reading CSV file, i found many solutions but i still got one problem. I need to read CSV file and then these values show in List Control and here i have problem. Idk how to display it in List?

View 4 Replies View Related

C :: Reading Values From File To First 2 Columns Of 2D Array / Assigning 0 To 3rd Column

Apr 4, 2014

I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.

I'm not sure for instance why on the bottom loop for line 1 it doesn't print:

temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1

Code:

#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");

[code]....

View 8 Replies View Related

C++ :: Reading From File And Store Values Of Each Line In Multiple Variables

May 6, 2013

So I have this text file that I am trying to read from and store the values of each line in multiple variables.

Let's say my text file contains

AXSYZ3482 Tom 100 112

and my code below here works fine when the lines in the text file is separated by spaces.

while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

But let's say my file was to look like this instead.

AXSYZ3482:Tom:100:112

But if i try this below...

while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}

It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.

So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?

View 2 Replies View Related

C/C++ :: File I/O - Reading Values From File

Jan 28, 2014

I am trying to write a program that will open a file with 2 points, take those points, determine what quadrant those points are in, and save the result back into the same file without truncating the data.

I'm having some trouble with my file I/O. I can't get my program to read the two values for X and Y that I put in the points.txt file. It simply uses whatever random number was used last time in that block of memory. In my points.txt file I put something like "4 -5" and it wont assign those numbers to my X and Y variables. I believe the issue is on line 25

#include <iostream>
#include <fstream>
using namespace std ;
int main() {
//defining X and Y
double X, Y ;

[Code] ....

View 14 Replies View Related

C :: Possible To Print Float Values Without Decimal Point?

Apr 8, 2013

I was going through the exercises in one C programming ebook.There is this question which asks me to print a float variable in fixed decimal notation, field size of 6, right-justified, no digits after decimal point.I got printf("%6f", x );

x = float variable.

But the above code prints numbers after the decimal point, so I changed it to %d. But %d doesn't work with float variables..

View 2 Replies View Related

C :: Convert Strings From Hex Values To Decimal Equivalents

Feb 8, 2014

I understand most of program below. Essentially, we have strings that we want to convert from hex values to decimal equivalents. We check if first two characters of string are 0x or 0X, which signifies hex format. If our hex string consists of solely digits like 0x25, then the processing is simple. We take the digit assign it to answer variable, and for each additional position in the hex base-16 system, we multiply the digit by 16.

Now if the hex string is something like 0x2A, then for 'A', the hexalpha_to_int() function is called, since we are able to find 'A' in the hexalpha string, we take the value of 'A', which is ascii 65 divide it by 2 and add 10 to it: 65/2+10=42.5. This doesn't make sense. What is the purpose of this logic right here: 10 + (i / 2).

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

int hexalpha_to_int(int c){
char hexalpha[] = "aAbBcCdDeEfF";

[Code] ....

View 1 Replies View Related

C# :: How To Insert Decimal Values In MySQL Database

Feb 26, 2014

i wanted to insert Decimal Values in MySQL database, but decimal values has precision and in C# there is not option to specify precision point, the last column is size which is integer.

MySqlParameter MySqlParameterCollection.Add(string parameter Name,MySqlDBTYPE dbType,int size);

Here my Code and i get error on last Line

MySqlCommand insert = new MySqlCommand("Insert into
Plan(Plan_ID,Plan_Title,Plan_rate,Plan_Length)
values(@p_id,@p_t,@p_r,@p_l);", con);
insert.Parameters.Add("@p_id", MySqlDbType.VarChar, 10).Value = p.p_id;
insert.Parameters.Add("@p_t", MySqlDbType.VarChar, 45).Value = p.p_title;
insert.Parameters.Add("@p_r", MySqlDbType.Decimal,10,2)=p.p_rate;

View 7 Replies View Related

C# :: Align Integer / Decimal Values On The Left (Devex Gridview)

Mar 22, 2015

I want to learn ow to align an integer/decimal values on the Left inside devexpress gridview.

View 4 Replies View Related

C/C++ :: Reading And Printing 2D Array?

Apr 10, 2015

I have a program where I need to read in a 96 number .txt file and perform some operations on it.However, the numbers it reads in are all inncorrect. I got it to work in XCode, but it doesnt work in DevC++ which is where the teacher will be running it. Do I have any major error?

#include <stdio.h>
#include <stdlib.h>
#define rows 8
#define cols 12
void makeArray(FILE*,int[][cols]);
int getScore(int[rows][cols],int,int);

[Code]......

View 14 Replies View Related

C++ :: Printing Vector Values Preceded By

Apr 17, 2014

Why does this generate an error:

Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( " " , std::cout ) ); whereas this works fine:
Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( std::cout , " " ) ); I know I can use this instead:
Code: for ( std::vector<double>::iterator it1 = vec.begin( ); it1 != vec.end( ); ++it1 ) std::cout << " " << *it1;

View 5 Replies View Related

C :: Reading From Stdin And Printing - Segmentation Fault

Mar 8, 2013

I'm writing a program that reads from stdin and prints it back out. I'm getting a bunch of garbage then a seg fault.

Code:

double numbers[256];
memset (numbers, 0, sizeof (numbers));
for (;;) {
double num = scanf ("%255lg", numbers);
if (num== EOF)
break;
}
for (int i = 0; i < (int)sizeof (numbers); ++i) {
printf ("%g
", numbers[i]);
}

View 3 Replies View Related

C :: Drawing A Box With Coordinates - Printing Between Certain ASCII Values

Sep 23, 2014

The assignment is:

1) Write a program that asks the user for a a single character and two XY coordinates. The two X and two Y values should all be integers between 0 and 50. The character should be a printable ASCII character with values between and including ' !' (ascii value 33) and '~' (ascii value 126).

2) Your program should then draw a rectangle made up of the user selected character where the upper left corner is at X1; Y 1 and the lower right corner is at X2; Y2. Be sure to print the appropriate number of blank lines (having spaces in the blank rows is OK) in the beginning and pad each row of your rectangle with X1 leading spaces.

The Output is supposed to be similar to this:

(X1,Y1) = (0,0) , (X2,Y2) = (4,4), the character = ^

^^^^
^^^^
^^^^
^^^^

What I am having trouble understanding is printing between certain ASCII values (ASCII has never been discussed in class).

Another thing I am having trouble with is the main part of the assignment. From what we are currently discussing is loops and the assignment is covering nested loops. My code looks similar to this:
Code:

#include <stdio.h>
int main (void) {
int X1, Y1, X2, Y2;
char cRec;
printf("Enter a character: ");
scanf("%c", &cRec);

[Code] .....

My thinking on the assignment is that you want the X1 coordinate to increase to the value of X2 (same for Y1 and Y2). Is this thinking wrong?

View 12 Replies View Related

C# :: Printing All Values Above The Diagonal Line In 2D Array

Apr 11, 2014

I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:

{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}

I'd have to print the elements in italics. I've tried this:

for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}

with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.

View 2 Replies View Related

C/C++ :: Reading From A File Line By Line With No Specified Number Of Values

Apr 12, 2015

Im trying to read from a file, line by line, with no specified number of values in the file. Check out my code:

int main() {
string x;
ifstream fin;
int count = 0;
char ch;
fin.open("CWC_Master.txt");
if(!fin)

[Code] .....

Now, this works great! However, its skipping some lines. And I dont know why. For example: Lets say that the input file is:

superman toy
sm2335
19.99
batman toy
bm5532
25.99
aquaman toy
am6786
26.00

Where it should output the above, instead it outputs every other one. Like:

superman toy
19.99
batman toy
25.99
aquaman toy
26.00

How can I fix my code so that it SIMPLY(i say simply because I am still a beginner coder) can read line by line?

View 7 Replies View Related







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