C++ :: File I/O Not Recognizing Contents Correctly

Nov 17, 2014

I have a program that's not doing what I want it to do. This is the assignment:

The nth term of the sequence of triangle numbers is given by, tn = 1/2 n (n+1); so the first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55,...

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.

the 'words.txt' has a bunch of words in this format:

"ABSTRACT"
"YOUTH"

there's about 1000 words in that format.

And for any triangle words I find, I put it into another text file which I called triangle.txt.

Now for my program, it pulls the 'words.txt' file just fine but it doesn't recognize any of the words in the file as triangle words.

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
int getCharValue(char a);
double sum1(std::string name);

[code]....

View 2 Replies


ADVERTISEMENT

C++ :: Compiler Not Recognizing Numbers

Sep 8, 2013

I'm working on this homework assignment where the program takes in the user's height in inches, weight in pounds, and age, then calculates their hat size, jacket size and waist size. The formulas for these are as follows:

Hat: (weight/height) x 2.9

Jacket: (height x weight)/288 then adjusted by adding 1/8 an inch for every 10 years over the age of 30 (The adjustment only takes place after a full 10 years, so there is no adjustment for 30-39, but there is for 40)

Waist: (weight/5.7) then adjusted by adding 1/10 of an inch for each 2 years over the age of 28 (the adjustment only takes place after a full 2 years, so no adjustment for 29, but there is for 30, etc)

I'm supposed to utilize functions for each of the three formulas.

There's a couple things I can't figure out.

1. Why won't the compiler recognize 2.9 and 5.7 as numbers?

2. How do I adjust the calculation for the jacket and waist based on age?

Here's what I've got so far:

#include <cstdlib>
#include <iostream>
using namespace std;
double hatSize(int weight, int height);
double jacketSize(int weight, int height, int age);
double waistSize(int weight, int height, int age);

[code]....

View 1 Replies View Related

C# :: While Statement Not Recognizing Non-null String

Oct 10, 2014

The List[] array contains some empty entries but most are filled, yet every time I run this routine the variable Index makes it to the end of the array. I've tried many different routes and can't seem to figure out this simple issue.

string Result = string.Empty;
while ((Index < (List.Length - 1)) || !string.IsNullOrEmpty(Result))
{
Result = List[Index];
Index++;
}
return Result;

View 9 Replies View Related

C++ :: CPP File Not Opening Correctly?

Nov 2, 2014

When I try to open the cpp source in Visual Studio, it just opens a blank notepad window. The cpp file says its 4 kb and there was code in it.

View 5 Replies View Related

C :: Linked List Program Not Recognizing A Function

Oct 22, 2014

I'm writing a linked list program for class that has a simple text based menu and I believe I am nearly done, it just wont recognize my "count" function as a function and I don't know why. The error comes up at line 70.

Code:

#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int datum;
struct node *next;
} node_t;

[code]....

View 3 Replies View Related

C++ :: Intellisensor Not Recognizing String Data Type

Apr 26, 2014

So Im working on my semester prject for my programming class. It is to make a roulette game. And Im working on getting my table set up but the intellisensor in my Visual Studio seems to not be working and recognizing the string variable type. Its not changing to blue when I enter it.

This program is a roulette simulation, designed to be used for online gambling.

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <string>
#include <ctime>
using namespace std;
//Function Prototypes
void welcome();
double getBalance();

[Code] .....

When I run the program it gives me an error as well sometimes. This one: Unhandled exception at 0x0f681f68 (msvcp100d.dll) in Roulette Final Project.exe: 0xC0000005: Access violation reading location 0x8bb59d35.

Which opens another tab named "iosfwd" and points to this bit of code:

static int_type __CLRCALL_OR_CDECL to_int_type(const _Elem& _Ch)
{// convert character to metacharacter
return ((unsigned char)_Ch);
}

View 5 Replies View Related

C :: Why Can't Get Info From Text File Correctly

Dec 21, 2013

the info gotten from the text file are all wrong, i can't find any problem with my code,

Code:

#include<stdio.h>
FILE *f;
typedef struct prd {
char name[30];
char code[30];
char idt[30];
float price;

[code]....

View 7 Replies View Related

C :: Printing Contents Of A File - Prints One Extra Character Not Present In The File

Feb 12, 2013

I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)

_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60

When printed out, the names are formatted as follows:

lastname, firstname: 90
lname, fname: 100
last, first: 60

However, when I print them out this is what I get:

lastname, firstname: 90
lname, fname: 100$
last, first: 60H

For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.

Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {

[Code]......

View 6 Replies View Related

C :: How To Read Data In A File And Print It Then Copy Contents To A File

Mar 8, 2013

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.

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

Visual C++ :: CFileDialog Does Not Display File Name Correctly

Sep 13, 2013

I haven't seen this before but on Windows 7 Home Professional and VC 2012 in one particular app, a CFileDialog displays only the rightmost 11 characters plus the extension of the default file name. The rest of the name is there and you can scroll left in the file name edit to display it all, but initially the text is shifted left so it doesn't all display.

Code:
CFileDialog dlg(TRUE, "csv", strFileName, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, "Comma Seperated Values Files (*.csv)|*.csv|All Files (*.*)|*.*||");

strFileName can contain anything and it will do it. Even a string literal will do it.

View 3 Replies View Related

C/C++ :: Program To Emulate Shopping List - File Not Reading Correctly

Jan 28, 2015

I have written an program to emulate a shopping list. Everything works fine, until I try to read in from a file. Here is my read and write code (the write code looks like it is working ok, but I figured I would include it just in case), and an example of what happens to a list that has been written, then read back in.

I took this list, and wrote it to a file, then read that file back in. The .txt file looks like everything was written out properly, but when I try to read that exact same list back in, this is what I get:

View 10 Replies View Related

C++ :: Encrypting Contents From File And Saving To Another File

Mar 17, 2013

Right now I'm working on an assignment where I need to take the data from on file encrypt it by adding 5 to each byte and then save it to a user specified location. I think I'm close to having it done but I've run into a hick up. After I get the user input for where the encrypted data should be saved the program seems to never end. This is the code I have so far

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream input;
ofstream output;

[Code]...

View 1 Replies View Related

C :: Read File Contents From EOF

Jan 8, 2014

How can I read contents of a file from the last character? Can I use a loop?

View 10 Replies View Related

C++ :: How To Read XML File Contents In CPP

Jan 30, 2015

I need a sample program to read contents of any xml file using CPP.

View 2 Replies View Related

C++ :: Get Output From File Contents

Dec 30, 2013

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
#include<graphics.h>
void input();
void output ();

[Code] ....

View 1 Replies View Related

C++ :: Zero In List Contents And Multiset Contents

Apr 24, 2015

HTML Code:

So I insert values from a vector into a list and into a multiset, and I noticed zero is added to their contents! I had to do a whole lot of debugging to find out where the error was, how can i stop this thing? Code which generates such error...

infact i checked the content of vector ups to be sure that there was no zero in it, but after loading into list combi_t * head, it seems like there was a zero added and this is giving me errors when i call function master_roller...

Code:
void ins(combi_t * &testa, int &numero, int &num, int &no)
{ // if (ricerca(testa, numero) == 0)
//{
combi_t *temp = new combi_t;

temp->val0 = numero;
temp->val1 = num;
temp->val2 = no;
temp->nextPtr = 0;

[Code] ....

View 2 Replies View Related

C :: Return File Contents As String?

Oct 1, 2014

I am trying to code a function which will read a file on system and return its content back as string. Code is below.

Code:
char * readtxt(){
FILE * fptr;
char c;
static char txt[30];

[Code]....

I suppose txt variable is pointer. But I need to return the file content as string so the function structure should look like

Code:
returnType function(){
return "File Contents as String";
}

View 13 Replies View Related

C :: Show Contents Of A File On Screen

Nov 22, 2013

The aim will show on the screen but does not show the contents of a file on the screen different shows.

Code:
#include <stdio.h>
#include <conio.h>
main() {
char filename[100];
double xx;
int ii, kk;

[Code] .....

View 12 Replies View Related

C++ ::  Writing Pointer Contents Into File

Apr 15, 2014

I have a character pointer that points to 4000 bytes of valid data. I need to write these valid contents pointed to by this pointer into the file. I am looking for the most optimized way of doing this. I am using the below logic which seems trivial. Any better approach to accomplish the same?

/* length is the number of valid bytes of data */
void parse_contents(const char *data, int length) {
int j = 0;
char path[1024] = "/tmp/data.xml";
FILE *fp = NULL;
fp = fopen(path, "wb");

[Code] ....

View 2 Replies View Related

C++ :: Copying Binary FILE Contents Into Another

Jan 10, 2013

How does one go about copying one binary FILE variable to another in C++? Say I have the following:

FILE* tempFile; //is a binary file and assume already filled with contents
FILE* localFile;

tempFile, as the name implies, is stored in a temporary directory (AND has a randomized temp name) within Windows and I want to copy its contents to another file with a predefined name that is within a valid local directory (e.g. C:UsersuserMy Documents est.exe). What do I have to use?

View 3 Replies View Related

C/C++ :: Return File Contents As String

Oct 1, 2014

I am trying to code a function which will read a file on system and return its content back as string. Code is below.

char * readtxt(){
    FILE * fptr;
    char  c;
    static char txt[30];
    int len=0;  
    fptr = fopen("C:UsersTestDesktopDev est.txt", "r");  

[Code] ....

I suppose txt variable is pointer. But I need to return the file content as string so the function structure should look like

returnType function(){
return "File Contents as String";
}

How can I achieve this ?

View 2 Replies View Related

C++ :: Read And Write Multiple Class Objects From File - Fstream Won't Work Correctly

Apr 28, 2014

So I have a small program which is supposed to write and read multiple objects from a file, but for some reason it doesn't write the information when I use "fstream" to create the object from the fstream class, but it does when I use "ofstream". Also, it doesn't read the information from the file no matter if I use "fstream" or "ifstream". I watched a video where this exact code worked just fine, but it just won't work when I run it. I'm using Dev C++ 4.9.9.2, I don't know if that has anything to do with it, I also tried it with Code::Blocks, didn't work either.

Here's the code.

#include <iostream>
#include <fstream>
using namespace std;
class Person

[Code].....

View 3 Replies View Related

C :: Losing Contents Of A String Between File I/O Operations

Oct 24, 2013

Here's the code I'm writing:

Code:
#include <stdio.h>
#include <stdlib.h>
char* getTeamCode(char* team);

[Code]....

Why the placement of the code on line 21 above matters.

It grabs the correct string just fine. If I write a printf just below it, it prints the string it should correctly. However, if I do a printf of the string OSUteamCode below the fopen call on line 23, it prints blank.

So the first thing I did was move it below the fopen line. It worked, finding and outputting the first game in "game.csv" just fine, but not the other 11. Debugging with printf shows that the contents of OSUteamCode again disappear after the fopen call in the addLineCSV function.

I'm not understanding why that happens. The only thing I can figure is there's something going on with the file I/O commands that I just don't understand, but I can't find anything online that explains what that might be.

View 3 Replies View Related

C++ :: Transfer Contents From Text File Into A String

Apr 9, 2014

I'm making a program in which it will read an input from a text file and then count the numbers of spaces , characters , words . Here is what i think it would work : First i will transfer the contents from the input.txt into a string , after that i will create 3 strings which contain each of these : spaces , characters , words . Then comparing each of the contents of the intput.txt_string to the other 3 strings .

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

[code]....

and of course it doesnt seem to work...

View 1 Replies View Related

C++ :: Reading From A File And Displays Its Contents On Console

Oct 18, 2014

Having some trouble with an assignment. Here is the prompt. Write a program that reads the telephone.dat file and displays its contents on the console. The program should allow the user to add new entries to the file.

I have saved the file into a resource file within visual studio and I am trying to run the code to where the file will be shown when I run the program. I know that the program is running and the file is there because if i misspell the filename it will give me the error message. I don't know how to make the contents of the file display. Here is what I have so far.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inputFile;

[Code]...

View 15 Replies View Related







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