C :: Parse Error / What Value Does Get Assigned
Dec 10, 2013
I get the following parsing error for the code
Code:
#include <stdio.h>
int main()
{
int i=3,4;
printf("%d",i);
return 0;
}
what is wrong with the code? I have put initialize value as 3,4 just to understand what value does i gets assigned.
View 5 Replies
Nov 9, 2012
Once again i hit a very simple problem i am unable to resolve. I using Visual Studio 2010, but am compiling for C.
This:
Code:
char i=45;
while(i=getchar() != EOF)
{
should imo work perfectly (yes, no real code, just to demonstrate the issue), but it doesnt. Getchar() always returns 0x01. Why is that? This, in contrast, works perfectly fine:
Code:
char i=45;
while(i!= EOF)
{
i=getchar();
Shouldnt an assignment always return the assigned value?
View 2 Replies
View Related
Dec 7, 2014
I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).
error: 'TicTacToe' was not declared in this scope
main.cpp
#include <iostream>
#include <cstdlib>
#include "Signature.h"
#include "Gameplay.h"
using namespace std;
// Initialize array
char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
[code]....
View 4 Replies
View Related
May 16, 2014
Suppose i have a text file with ":" as delimiter, how to i find the average value of each column? For e.g. First column will be (3+2+5)/3 and second column will be (61+87)/2 for the third column.
Sample text file
================
3:290:61:100:
2:50:
5:346:87:
I have tried using getline in while loop, but it seemed more complicated because i think it requires much more than that.
View 2 Replies
View Related
Mar 22, 2014
I am using TinyXML 2 for the data of my RPG game, I am almost done with the tilemap parsing system, but I just couldn't figure out how to extract csv data that I have in my XML file, like this:
<data encoding="csv">
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
[code]....
What I want to do is to extract this data using TinyXML 2 and to put the data into a 2D vector...how can I do that?
View 9 Replies
View Related
Feb 27, 2015
I have a 3-dimensional matrix(3,3,3) and want to write it to a file. I have the code for parsing it in a compatible for matlab format. But at this point i want to use a pointer to do the same thing.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
const int dimx = 3, dimy = 3;
int i, j;
unsigned char a[3][3][3] = {
[Code]...
If it is a 1-dimensional array i can understand the logic.
Code:
int val[7] = { 11, 22, 33, 44, 55, 66, 77 } ;
int *p;
p = val[0];
for ( int i = 0 ; i <= 6 ; i++ )
[Code]...
View 3 Replies
View Related
Jul 31, 2014
I am trying to parse a text file that contains information and i cant seem to get started. For example, the text file looks like this:
idx=929392, pl= 12, name= someperson
age=19
state=ma
status=n/a
idx=929393, pl= 12, name= someperson2
age=20
state=ma
status=n/a
idx=929394, pl= 12, name= someperson3
age=21
state=ma
status=n/a
I want to parse the name and age into another text file like this format:
someperson 19
someperson 20
someperson 21
possibly include other attributes next to the age like idx?
View 3 Replies
View Related
Nov 14, 2014
I have this project for school where I basically need to write a program that will take any text file and convert it into html code.
string line;
int lineCount = 0;
while (!inFile.eof()) {
getline(inFile, line);
cout << line << endl;
lineCount++;
}
cout << lineCount - 1 << " lines of text read in this file." << endl;
I have this block of code to print each line of the text file into the terminal window and count the number of lines printed. But I don't know how to make it change a single character or set of characters to something else. For example, if a line of text begins with the number "1", I want to be able to change it to "<h1>".
View 2 Replies
View Related
Nov 23, 2014
I'm trying to make a program where it reads a text file which contains "blocks" of questions like:
Type: multiple_choice
Question
Num_options: number of options
a) option1
b) option2
c) option3
d) option4
Letter of answer
and
Type: short_answer
Question
Answer text
what I'm trying to do is use parse those blocks and have it get handled by the classes, MultipleChoice and ShortAnswer.
I'm planning on using getline as a virtual function and have an if statement like
"if (string == "multiple choice)
** then get it handled by the MultipleChoice class "
View 10 Replies
View Related
Sep 3, 2014
I'm a student. I've complete an exercise where the goal is to parse some user input to output phone numbers using EXACTLY this style (not including the quotes): "1-888-8888".
Some rules that I've set for my parser are,
1) the phone number can be mixed in with other text, e.g. "My number is 38888888" or "1asdfk8888888" and
2) the first number found must be a valid calling code (1-9).
I wanted the parser to be flexible. Is this nesting too deep?
std::string format_phone_num(std::string &s) {
std::string formatted_num = "";
bool call_code_found = false;
short num_count = 0;
for (unsigned int i = 0; i < s.length(); i++)
[code].....
View 4 Replies
View Related
Feb 20, 2015
I have a text file which contains many sentences. I am trying to extract only the numerical values from the string that conatins characters,numbers and white spaces from the file. I want to seperate the characters and numbers into different parts.
for example: the file contains sentances as given below.
I have to go to school for 10min.
You will come here in 15min.
He stayed here for 20min.
from the above sentances, I want to seperate " I have to go to school for " and "10" and put them into two different variables and also 10 should be in integer format.
View 1 Replies
View Related
Mar 12, 2015
I am working on a program where I am reading in a text file to be parsed to load data objects into their appropriate classes. I have a class to load in this file and to parse its contents. I am at the point where I would like to include the ability to have both C and C++ style comments in this text file. My current class has a constructor that takes in const std::string for its file name. Upon construction I have a while loop that calls a member function getNextLine() as long as this is true this loader class object then calls parseGui(). All of this works correctly so far. Within the function getNextLine() looks like this:
// ----------------------------------------------------------------------------
// getNextLine()
// Returns True If It Got A Line Of Text (Could Be Blank If It Is All Commented Out Or
// If It Truly Was A Blank Line). False Is Returned When There Is No More Data In The File
bool GuiLoader::getNextLine() {
if ( !_file.readLine( _strLine ) ) {
return false;
[Code] ....
As you can see this getNextLine() method reads in a single line of text and saves it into its member variable which is a std::string. It increments the line number, then a utility function trims out leading and ending white spaces. The next part is where this class calls a member function to remove comments. It is in here where I need to parse the string to look for comments either "//" C++ style line comments or "/* ... */" C style block comments that can span multiple lines. I have tried many different ways to go about doing this, and I am stuck on the C style comments. A note to consider is this: the way this code is designed is reading in a line of text from the file into a string variable and in doing so it is not logical for me to read in the complete file and do a pre-parse scan or analyzer.
This is what I have so far, however there are still cases that this code will fail on
// ----------------------------------------------------------------------------
// removeComments()
void GuiLoader::removeComments() {
const unsigned tokenLength = 1;
static std::string::size_type indexA;
static std::string::size_type indexB;
const std::string commentStartingToken( "/" );
const std::string blockCommentStartingQualifier( "*" );
[Code] .....
An example of where this code will fail is when it encounters a single '/' any where on a line of text as it goes into an infinite loop. I am not sure on how to go about skipping this lonely '/' and advanced the index to look for a possible next '/' that belongs to a '//' or a '/*'. I know that this is sort of trivial, but for some reason or another I am having writers block.
View 14 Replies
View Related
Jun 6, 2014
I'm using the Split method to parse line in a csv file. The following code works if there are no commas in the text of my data.
string csvLine;
string[] splitLine;
csvLine = "Jim Borland,1234,Never dreams in code";
splitLine = csvLine.Split(',');
But if I have commas in the some of the text as below I get then wrong output. So I need split on a commas which are not enclosed in double quotes.
string csvLine;
string[] splitLine;
csvLine = ""Jim,C,Borland",1234,"Never dreams in code"";
splitLine = csvLine.Split(',');
The output I want is:
Jim,C,Borland
1234
Never dreams in code
I found this :
If your strings are all well-formed it is possible with the following regular expression:
String[] res = str.split(",(?=([^"]|"[^"]*")*$)");
The expression ensures that a split occurs only at commas which are followed by an even (or zero) number of quotes ... and thus not inside such quotes).
Nevertheless, it may be easier to use a simple non-regex parser.
But the .split gives me an error and .Split doesn't work either.
View 5 Replies
View Related