C++ :: Extract Comments From C File

May 21, 2014

I need to extract comments from a C file, which are usually marked with " /* This is a comment */ ". It seems to me that I need to calculate first at what position is the / and then ask it if on the very next position to the / operand is the *, if it is then I need check where is the next * and if / operand is immediately next to it. At last I need to take everything between values that the first and second * have. But I don't know how to write that in code.

This was supposed to be done in c++.

View 5 Replies


ADVERTISEMENT

C++ :: Remove Comments From Input File And Then Put It Into Output File

Mar 11, 2013

I have written this code to remove the comments from an input file and then put it into an output file. The program compiles and runs but it removes the whole line of code when it encounters a /* */ type comment. I believe the problem is in the while loop but I just don't know where.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(void) {
string infile, outfile;
ifstream source;
ofstream target;

[Code]...

View 3 Replies View Related

C/C++ :: How To Parse Contents Of File To Remove Comments

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

C++ :: How To Take Comments From C File And Store It In Text File

May 16, 2013

C++ code that will take the existing comments from a arbitrary C file, and store those files in a text document?

View 4 Replies View Related

C :: How To Extract Data From Txt File

Jan 13, 2015

I managed to read txt files and printing them on the console window. I was given a task to select and sample a certain amount of data.

Example of txt file:

Voltage (V),Current (I),Power (W)
50,2,100,
51,2,102,
52,2,104,

etc.. How can I display only the column of Voltage and Power?

View 1 Replies View Related

C++ :: Extract File Name And Extension From TXT?

Aug 10, 2012

I have a list of files stored in a .txt file

$codeguruc++display.txt$15$

Directory File Folder: codeguruc++
File Name: display.txt
File Size: 15kbs

$ is an delimiter

I want to extract the name and the extension from txt files.

Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
struct MyFile {
std::string Directory;
std::string Filename;
unsigned filesize;

[code].....

View 6 Replies View Related

C++ :: Extract Certain Cells From Excel File?

Apr 9, 2013

how to extract certain cells for an excel file that is continuously updating. I had a look at [URL] since they provide a .h library that is useful for this situation, but could not find any code.

View 7 Replies View Related

C++ :: Iterate Through A File Path To Extract File Name

Feb 20, 2014

I am trying to iterate through a file path to extract the file name. since the . separating the name from the extension is a unique character, i thought i would reverse iterate from the . to the first separating directories. however, when trying to reference the memory location of the position of the . in the string, i am getting an i-value error:

for (std::string::reverse_iterator iter = &(songPath.find('.')); iter != songPath.rend(); ++iter) {
if (*iter == '')
break;
else
songName.push_back(*iter);
}

View 3 Replies View Related

C/C++ :: Search In File And Extract Content Between 2 Strings

Jun 8, 2014

I need to develop a simple program, i have 2 variables (begin, end), and i need to search in a file, And extract the string between the Begin and the End variables to a new File, For Example:

my text file: file.txt:

some text here<StartHere>more text here</EndHere>text text

C++ Program:

//Declear 2 variables
strcpy_s(begin, string("<StartHere>").c_str());
strcpy_s(end, string("</EndHere>").c_str());

//And now, search in the Text file, And Extract the text between the begin string and the End string.
<...>

The Result should be: NewFile.txt with the content:

<StartHere>more text here</EndHere>

That's it!, Here is what i have for now:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
int ocurrences_count = 0;
int ocurrences2_count = 0;
char word[20]; //this array will save user input

[Code] ....

View 1 Replies View Related

C++ :: Program To Extract Numbers From A File That Is Always Updating With New Data

Mar 14, 2013

How to write a C or C++ program that extracts certain numbers out of a section after the 4, 5 and 6 space.

For Example:

The output file will produce:

[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.274000 0.010000 54 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 18];...

So I want to extract the numbers 0.650000, 0.006000, 0.020000 because those are the 4,5,6 space after [ [

Another problem I have is that the output file I showed will always being updated constantly for instance as follow:

[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.2054000 0.010000 10 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 13];...

[ [1900 00 0 -1.000000 0.650000 0.006000 0.020000 2.694000 0.010000 9 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10];...

[ [1900 00 0 -2.000000 0.6023000 0.04000 0.050000 2.2454000 0.010000 5 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 12];...

And it will keep updating like this and I want to update the previous numbers I extracted with now the new numbers after the 4,5, and 6 space.

So I have to write a code to let it know when it encounters [ [ start looking for the 4,5,6 space and get those numbers and once it reaches ;... that's the end of that section so re-look for the next section of numbers after the 4,5,6 space.

The file will be a text file or matlab file that is always being updated with these sections of numbers. Can I make this a #include<nameoffile.h> or does .h not work with a file that is always being updated.

View 2 Replies View Related

C++ :: Header File That Is Continuously Updating To Extract Certain Variables?

Mar 10, 2013

I need to write a C++ program, that extracts certain variables, x y z, from a file that is continuously being updated x y z. These variables are going to be used to recalculate a new answer.

My question is to see if it is possible to have an include .h file that is always being updated so that I can extract these three variables from it, and always have the newest venison of each variable, so that the answer to the equation is always the newest updated. Should I use fopen or fwrite to do this.

View 4 Replies View Related

C++ :: Output Unicode Number If Extract A Character Off A Console Or Out Of A File

Oct 31, 2014

How do I output a Unicode number if I extract a character off a console or out of a file.

If I do the below, I use the Unicode number to show a character. The below shows me 25² .

char b = 'u00B2';
mystring = "25";
mystring.append(1,b);

How do you go back the other way? If I extract the 25 and the ² separately, how do I get the unicode number for ² ?

View 3 Replies View Related

C++ ::  Program Shouldn't Count Comments And Blank Lines

Feb 7, 2015

My program does compile and counts the number of lines of code, which is LOC: 20. My issue this, according to my code instruction it should not count comments (//) and also shouldn't count blank lines of code. Unfortunately my code is counting // and white space.

What seems to be working is #, all three includes are not being counted. That’s a good sign. I’m using the same technique not to count #. Why isn't working for comments and blank lines? I’m pretty sure that my logic is correct. I think my problem is maybe syntax.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
//read my file

[code]....

View 4 Replies View Related

C++ :: Uncomment Statement - Execution With Cout Statements As Comments Breaks

Jan 21, 2013

when i uncomment statements in the following ,it works perfectly fine for infix to postfix conversion.although comments are simple cout statements,, execution with cout statements as comments breaks in b/w.I have found this particularly with a^b-c.DevCPP is also showing similar behavior. I can't understand what's going on.I am working on code blocks.

#include<iostream>
#include<cstdio>
#include<conio.h>
using namespace std;
char stk[15];

[code]....

View 2 Replies View Related

Visual C++ :: Program Shouldn't Count Comments And Blank Lines

Feb 7, 2015

I'm making some progress. My program does compile and output the number of line per code, but it shouldn't count comments and blank lines. I tried using (s.substr(0,2) == "//") as suggested but it didn't work.

This is my improved code:

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int A = 3;
int main() {
string s;

[code].....

View 1 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

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

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: How To Extract Output From IF Statement

Feb 9, 2015

I need to use the output of my IF statement in a calculation. But how can i extract the output from the IF statement in my code?

#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[]) {
double x, y, z;
cout<<"Please enter the student's three test grades:"<<endl;
cin>>x>>y>>z;

[Code]...

I need to use the output in my average.

View 3 Replies View Related

C++ ::  How To Extract And Modify Sub-Vector

Jun 17, 2014

I have a std::vector<int> and I want to modify subset of the elements. I thought I might be able to use:

std::vector<int> a = { 1,2,3,4,5,6,7,8,9 };
std::vector<int> b(&a[3],&a[7]);
for(auto& each : b) {
each++;
}
for(auto& each : a) {
std::cout << each << "
";
}

but that didn't work. The elements of 'a' retain their original values. Then, I thought, "Ooo, maybe I could make 'b' a reference." Nope. What approach would be to access a subset of a vector for potential alteration?

View 3 Replies View Related

C++ :: Extract Text To Vector?

Apr 5, 2013

im trying to extract this

1 2 3 4
5 7 8
9 6 10 11
13 14 15 12

into a vector where the blank space can variate and the numbers can switch.How can i get this working?

View 1 Replies View Related

C++ :: Extract Some Images From ADF Files

Jul 31, 2013

Its to extract some images from .adf files, I have had it working about 2 years ago but now i cant figure out the right directory.

Code:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
namespace ADFReader{
class Program {
public static int ApplyOffset(int data, int offset)
[Code] ...

The main problem is

Code:
static void Main(string[] args) {
foreach (string file in Directory.GetFiles(@"data", "*.adf")) ;
{
byte[] bytes = File.ReadAllBytes(file);

[Code] .....

View 1 Replies View Related

C :: Parsing A Line To Extract A Particular Substring?

Mar 14, 2014

Suppose I have read a line from an ASCII file with fgets(). Now I want to parse the line, which looks something like this: Code: # John Q. Public et al. 2014, to be submitted The name, "John Q. Public" is what I want. However, the name can be anything, consisting of 1 or more tokens separated by spaces. it could be "John" Or "John Public", or "Thurston Howell the 3rd", or etc... Bascially, I need to get the entire substring between the first hash mark, and the "et al" in the line. I tried this: Code: sscanf(line,"# %s et al.",name); But I can only get the first token (which, in this case, is "John").

View 2 Replies View Related

C++ :: Load PNG Files And Extract RGB Pixels?

Apr 18, 2014

How to load png files and extract their rgb pixels? Library recomendations?

View 2 Replies View Related

C# :: Extract Value From Stored Procedure That Takes A Parameter

Dec 17, 2014

I have a stored procedure, which I cannot change (it is used by older programs). It is passed an int of 15 and then an ID is generated and written to a database table. The created ID is then suppose to be selected and returned.

The INSERT does not seem to be working. I'm not getting the created ID value from my code, I am getting the value I passed to the procedure when I get to this

line of code "sessionID = sessionProcedureID.Value.ToString()";.

Below the stored procedure and my code.

/***************Stored Procedure***********************/
USE [testDataBase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MakeValue]

[Code] .....

View 14 Replies View Related

C Sharp :: How To Extract A String From Byte Array

Feb 11, 2014

i need to search for a keyword in a binary(.raw)file and have to extract the characters(until a '&' character is found)that immediately following the keyword .

View 1 Replies View Related

Visual C++ :: How To Extract Machine / Hardware ID And OS Version

Nov 19, 2014

Is there a way I can extract Machine / Hardware ID and OS Version using VC++?

View 3 Replies View Related

C++ :: Array Matrix - Extract Values Which Does Not Repeat

Jul 27, 2013

I have an array matrix called tmat,,and i know that in every row of tmax there are values which repeat two times...and am writing a code to extract the values WHICH DOES NOT REPEAT into another matrix called tcopy...the codes compiles fine...and it writes nicely to file...but without the desired result...

One last question...how can i get the array tcopy written to file in the form 5x3...and not all the figures in line one after the other? i mean i wish to see the matrix like a matrix on file..not like a list of numbers....

Code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int R = 5;
const int C = 5;

[Code] ....

View 14 Replies View Related







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