C :: Substitute String With File

Jan 20, 2015

I wrote the following code:

#include "stdafx.h"
#include "string.h"
#include "ctype.h"

int count_nonspace(const char* str)

[Code] .....

This program is checking how many times each character appears in a row but it uses string as a source of a text and i want to use a file. I am not very fluent in operating on files, thus my question is what should be change in this program to make it work on files, not only on strings?

View 4 Replies


ADVERTISEMENT

C++ :: Trying To Substitute A Variable For File Directory

Jul 1, 2014

I am trying to substitute a variable for the file directory. Here is the error: error: no matching function for call to 'std::basic_ ofstream <char>:: basic_ ofstream(std::string&)'

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

[code]....

View 2 Replies View Related

C++ :: Lagrange Interpolation Formula - Substitute Values Into Power

May 7, 2013

I did a function for lagrange interpolation formula. However i`m stuck on how do i substitute values into the power. Here is my code snippet :

for(int i=1;i<getSecretShare+1;i++) {
//calculateValue=getSecret+(10*p)+(2 * pow(p,2));
int storeThreshold=getThreshold;
calculateValue=getSecret+(10*i)+(2 * pow(i,2));
calculateFinalValue=calculateValue % 17 ;
cout<<"the calculated value is "<<calculateFinalValue<<endl;
}

The formula that i want to implement is that a + a1x^1 + a2x^2 + a(t-1) ^t-1

I have gotten the substitution of the x value out. However, i am stuck on how do i calculate the values according to the threshold which the user keys in. For example if the user keys in 3.

It will into account the no. of shares to generate which is for example 5 in this case, then it will then take into account the threshold keyed in , which is 3, i will then calculate using the formula using the no. of shares and also threshold.
if the threshold is 3 and the number of shares to generate is 5. I should have the following:

y(1) = 13 + a1(1)^1 +a2(1)^2
y(2) = 13 + a2(2)^1 +a2(2)^2

the power depends on the threshold which is t-1, 3-1 =2

So I will have to generate two a values based on that and also calculate them according to the power that is dependent on the threshold the first value being to the power of 1 and the 2nd being to the power of 2 if the threshold is 4.

Then I will generate 3 a values and then calculate them :

y(1) = 13 + a1(1)^1 + a2(1)^1 + a3(1)^3

and so on..

View 4 Replies View Related

C Sharp :: Finding String From Physical Memory Dump File (RAW File)?

Feb 5, 2014

I need to find a string(&login=) from physical memory dump file.And i have to print the word or string following it.Is there any C# code for this problem?

View 3 Replies View Related

C :: Reading From A File And Skipping Lines To Find String In File

Nov 26, 2013

Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.

The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.

The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.

The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)

The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.

The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.

The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.

The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:

If a patron buys a ticket at the door, a command will be on a line by itself:

BUY TICKET k

where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.

Code:

#include <stdio.h> #include <stdlib.h>
#include <string.h>
#define N 1000

[Code].....

View 4 Replies View Related

C++ :: UTF-8 File To String

Sep 20, 2013

I have a UTF-8 file, that looks like this:

/****** Script for SelectTopNRows command from SSMS ******/
SELECT COUNT(*)
FROM [a].[dbo].[Events]
WHERE [a].[dbo].[Events].EventID NOT IN(

[Code] ....

I read it in as so:

std::ifstream *streamqe = new std::ifstream("C:pathqueries.txt");
std::string szq((std::istreambuf_iterator<char>(*streamqe)), std::istreambuf_iterator<char>());

So, string szq is fine, except, that it contains a at the beginning of the string. How is that, and, what can I do to get rid of it?

View 5 Replies View Related

C/C++ :: How To Use A String As File Name

Apr 12, 2012

I am trying to create a file with variable name. In order to do that I use a string, I let the user scan for it, but the problem appears when I try to "fopen", since I am not sure for the syntax in this case.

View 1 Replies View Related

C :: Rewriting A File From String To Int

Sep 25, 2013

I've been working on a project where we are to take a file with lines of strings, and rewrite it with the same values in integers. I've tried it two different ways. The first way resulted in an infinite loop when it tries to put the data into an array (the first while loop):

Code:
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>

[code]....

View 9 Replies View Related

C :: Search File For String

Aug 22, 2014

I should state that I am recently new to C programming. I have dabbled with Python in the past, but nothing formal. I am taking a C programming class, but it is an introductory course. As such, the instructor is moving extremely slow through the material.

With this program, I am trying to search a given text file (line-by-line) for user-submitted data. I then want to be able to store which line that data was found on. The program runs, but it always results in "Sorry, couldn't find a match." Even if it shouldn't.

Code:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
}

[code]...

I should probably explain my overall goal with this program.I would like to write a program that will calculate the molecular weight of a compound. I expect the user entered molecular compound to be something like this: CH3COOH (An equivalent entry could be C2H4O2)Also, it needs to be case sensitive because the chemical formulas are case sensitive.

The output will be "The molecular weight of CH3COOH is xxx.xxxxx grams".I have two text files as well. One contains a list of all chemical symbols, and the second is a list of all atomic weights in the same order as the first. I want to place the user inputted data into an array, then search for each element of that array in the chemical symbol text file. It will show which line it was found on, then I can use that line to grab the atomic weight from the second text file.

View 5 Replies View Related

C++ :: Converting String From TXT File To Int?

May 6, 2014

How will I add the existing content of the text file to the newly inputed date(hoursworked & minsWorked) to compute the total number of hours works. I'm just a beginner in using Visual basic C++.

Code:

#include <iostream>
#include <fstream>
#include<string>
#include <cstdlib>
using namespace std;
bool parseTime(char* _timeStr, int& _hour, int& _min) {

[Code] ....

View 6 Replies View Related

C++ :: Check If A File Contains A String

May 5, 2014

If there is a simple way to check if a file contain a string?

View 1 Replies View Related

C++ :: Space File In String?

Mar 24, 2014

I have a problem, caught the last line of a file and do the division of the same variables in, date, time and value, but the file contains excess spaces in all lines and the date is coming with cuts, example 24/4/2014 appears 4/4/2014. How can I remove the space in the string without affecting the division of the line?

if (file) {
std::string line = getLastLine(file);
std::istringstream iss(line);
getline(iss, date, ' ');
getline(iss, time, ' ');
getline(iss, t); //variavel para temperatura em string
}
else {
std::cout << "error file
";

View 5 Replies View Related

C/C++ :: Sorting String From A File?

Mar 23, 2015

I am writing a code that is supposed to read a resistor code and determine the resistance nominal, lower, and upper and write those numbers to a file in various ways. I already accomplished writing to the file output and the file nominal but now I have to sort the file nominal by the nominal readings. I managed to tokenize the string so I could read the second part of the string .....

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
double bandNum(char x);
double bandMult(char x);
double bandTol(char x);
int main() {
FILE *pFile;
FILE *pFileOutput;

[code]....

View 4 Replies View Related

C++ :: Printing A String To A File?

Aug 24, 2013

these are the errors that I'm getting from an online c++ compiler

// main.cpp:4:10: error: #include expects "FILENAME" or
// main.cpp: In function 'void permute(char*, int)':
// main.cpp:17:9: error: 'f' was not declared in this scope

I don't understand how to print full_string to a file!// otherwise, I know that it gives the correct output -- 90 strings.

#include <string>
#include <iostream>
#include <fstream>
#include >ios> // line 4 error
using namespace std;
char full_string[] = "112233";

[code]....

//iter_swap – it just swaps the elements pointed to by the respective pointers without changing the pointers themselves. so, it's basically equivalent to the function:

void iter_swap(char *ptr1, char *ptr2) {
char tmp = *ptr1; *ptr1 = *ptr2;
*ptr2 = tmp;
}

// min_element – finds the location of the minimum element that exists in the given range. in this case,

it is the char* pointer pointing to the location of that element. it can be implemented like:

char *min_element(char *start, char *end) {
// end is 1 beyond the last valid element
if(start == end) return end; // empty range
char *min_pos = start;
for(char *iter = start+1; iter != end; ++iter)

[code]....

View 7 Replies View Related

C/C++ :: Convert File Name Into A String?

Feb 18, 2014

there is a way to convert a file's name into a string.

Sample:

filename = testcode.txt

it will convert the file's name into a string:

char convert[100];

covert = name of file

Is this possible?

View 3 Replies View Related

C++ :: Read String From The File?

Sep 23, 2014

I have an example text file that contains:

***xyz text********
***********<td>temperatura: </td><td class="data">19.8 °C</td>
***xyz text********
***********

How can i extract the number 19.8 from that file?

View 3 Replies View Related

C++ :: File Stream And String Extraction?

Apr 7, 2014

I am currently trying to read in a file that takes in the input in the following form.

Code:
HANK>25 BOB>31 AL>54
BILL>41 ABE>63 JEFF>50

I have tried the following solution:

Code:
#include<ifstream>
#include<iostream>
using namespace std;
struct node
{
string name;
int age;
);
int main ()
{

[code]....

The problem is a.name, it's extracting the entire string before the space character causing p.age to contain "BOB" and so on. I've tried using p.get(p.name, sizeof(p.name), '-') with '-' as the delimiter and p.getline() using a character array instead of a string. How would it be possible to only copy the string into a.name before the '>' character?

View 1 Replies View Related

C++ :: How To Display A String Per Line On TXT File

Mar 6, 2015

How can i display a string per line on the .txt i made? There are 2 .txt files, the one has: John Finn Xach The other is: password1 password2 password3 Question is: How can i display, let's say, i input "John" so it will display something like this "John's password is password1" or if i input Xach, "Xach's password is password3" When i use something like :

Code:

while(getline(passwordFile, str))
{cout<< username <<" password is " << str;
break;
}

It will work for when i input "John", but it doesn't work if I input "Finn" or "Xach"

EDIT: I tried this one:

Code:

while(getline(userFile, str1) && (passwordFile, str2))
{
cout<< str1 <<" password is " << str2;
break;

The output would be: Finn password is password1

It iterates the username but not the password.

View 7 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 :: How To Replace A String Of A Person In A File

Mar 6, 2015

I'm having a bit of problem. I've set the string 'Absent' to all student in a file. However, I want to replace 'Absent' with 'present' when the correct ID assigned to a student is entered. In other words, 'Absent' will only change to 'Present' for a specific person at a time. I'm not sure how to implement this

View 4 Replies View Related

C :: Assigning Line Of File To String

Mar 28, 2014

I'm making a game that requires the user to enter a correct username and password to play. I have a list of accepted ones saved in a txt file. How do i read each line of the file and check it with the one entered? I know how to use strcmp(string1, string2). I just need to know how to move from one line to the next. This is what I have for this part of the program so far. Also, I think im using the feof() wrong.

Code:
id = fopen("F://CS223/namepass.txt", "r");
score = fopen("F://CS223/scores.txt", "a");
srand(time(NULL));
if(id == NULL)
{
printf("ERROR");

[Code] .....

View 6 Replies View Related

C :: Fprintf Does Not Save String To File

Jan 3, 2014

Code:

struct sth {
char* str;
} pt;
}
[code]...

fprintf does not save string to file. How can I put structure into list?

View 9 Replies View Related

C :: Opening File And Copy String To That In Other

Jun 22, 2014

I am getting an error when i try to open FILE which user must enter then program must open that file i an function and copy string from that file in other .

Error is expression (stream !=NULL)

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

void FileCopy(char a[],char b[]);
void main() {
char a[40],b[40];

[Code] ....

View 8 Replies View Related

C++ :: Reading A File And Storing It In A String

Feb 7, 2013

I know how to do this in c++ with fstream and std::string and getline and so on and so forth. Im writing my code solely in c however. I can't get g++ installed so figured it was a good excuse to learn c instead of using the equivalent c++ abstracts.

My problem is, I'm making a game in c that I have made in c++ but have ran into an issue with my map. I want to read in my map from a file which just looks like this:
Name of Town
* * * * * * *
* * * * * * *
* * * * * * *
etc...

so i tried using fscanf to first read in the name of the town (stored in a char*) then read in the characters (in this case '*')(not including white spaces becuase i can just print those) into another char*. what is the better way to do this?

View 16 Replies View Related

C++ :: Input File And Store In String

Nov 22, 2013

I'd like to input a file and store the contents of the file in a string.

Here is my code:
std::string inputFile();
int main() {
std::string fileContents = inputFile();
} std::string inputFile()

[Code] ....

It works fine if the file name and path is input correctly.

But, if the file name or path is entered incorrectly, the recursive call to inputFile is executed, and the user is given another opportunity to enter the file. Then, if the file name is entered correctly an error is thrown in Visual Studio 2013:

"Unhandled exception at 0x77F7A9E8 (msvcr120d.dll) in Assignment4.exe: 0xC0000005: Access violation reading location 0xCCCCCCC0."

How could this be done better?

View 1 Replies View Related

C++ :: String Input AND Output To File

Sep 15, 2013

I'm trying to write a simple program that will prompt for a string typed in by keyboard and save it to a file. I've tried lots of variations and this is just the latest version.

//Prompt for a string input by keyboard and save it to a file

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

[Code] .....

View 2 Replies View Related







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