Visual C++ :: Looping Lines And Blocks Of Characters
Mar 17, 2013
I have a file that is like the following, with patterns of pipes in it:
Code:
||| || | |
| ||| | | |
|| || ||
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
How to get this done besides writing severely redundant control structures like loops, one after the other?
View 5 Replies
ADVERTISEMENT
Aug 14, 2014
I have a file that I need to read in blocks. I need to read in n lines at a time, do some processing, and then read in the next block of n lines until the file is done. I know the size of the block, but not the number of lines in the file unless I check that first. Normally I would read in like,
Code:
// declarations
string new_input_line, input_file;
// create an input stream and open the input_file
ifstream input_file_istream;
input_file_istream.open( input_file.c_str() );
[Code] .....
// process through data_block
With this approach, I'm not sure how I would keep looping to read the next block until I hit the end of the file without knowing how many lines are in the input file. I could process the file to find that out, or get that number from bash and pass it it as an argument, but it seems like that shouldn't be necessary.
I could also read in and store the entire file as a vector of string and then process through it afterwords, but that would not be a very efficient use of memory.
View 1 Replies
View Related
Feb 3, 2014
I am looking for a way to correctly count the lines between two specified characters/strings in a file. Here's the part I need work on:
getline( file, lines );
do {
if(lines.find("character")
{
++counter;
}
} while( !lines.find("story") );
I want the code to search for the first occurence of the word "character," and start counting the lines from that line until it hit the first occurrence of the word "story."
Right now, I am only getting a counter value of 1.
View 2 Replies
View Related
Mar 20, 2013
I am writing a program for my class in C++. For this program we are required to use different fuctions and prototypes outside of main. We have to determine the number of characters, lines, sentences, digits, words, etc. in a particular function the user types in.
View 1 Replies
View Related
Jan 31, 2014
I am writing a code to read a file and break it into lines and characters but I am getting an error do not know the reason for it though.
here is my code
#include<fstream>
#include<string>
#include<iostream>
[Code].....
The first line is executing properly but when it goes to the second line I get an error "the program has stopped working"
View 1 Replies
View Related
Aug 30, 2014
Simple program to convert files to XML files. However I am trying to narrow down why my code is not working. I am reading a line that looks like "2001 Joe Dirt Los Angeles", then the next few lines are followed by text and the the fifth line looks like "---End of Description---".
So here is the file
2001 Joe Dirt Los Angeles
Home is where you make it
Best movie ever(but not really)
But seriously
---End of Description---
Here is example code to test the process
string line;
while(dataFile >> line) {
getline(dataFile, line);
cout << line << endl;
}
My returning output is
[space]Joe Dirt Los Angeles
[space]Home is where you make it
[space]Best movie ever(but not really)
[space]But seriously
My test code is skipping the date on the first line but replacing it with a space. Then it is skipping my fifth line which reads "---End of Description---". Now if I take the code out of the while loop and hard code in five lines of output (x5 getline(dataFile,line); cout << line << endl;) then my code works as expected. I get all of the information. Date and the fifth line.
It looks like when I am testing for the EOF it is also taking in the numeric value at the beginning of the first line. However, that does not explain why it is dropping that fifth line.
View 3 Replies
View Related
Dec 17, 2013
I have to write a program (on linux) which will count character, words and lines like wc linux command. I'm trying to write this for last 3 days... First part of app I did and it works fine - command line options to choose. Then I've got a function read_file which I have to use to read a file. One of the options is to get the file name from user and if user will not type any name then the standard file is ubuntu dict file /usr/share/dict/words, this is not working as well...
Counting characters and lines is working fine but because I don't know how to get text from read_file wrote code to read file interior this functions. Words counting is working partly - everything is fine until there are two or more spaces, tabs one after another then counts extra words. Finally I need child processes in words and lines counting functions. Parent process should waits for all childs to finish and should be pipes to submit character counts back to parent process. How to do all this things with processes...
Code:
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/*size of character buffer to read in a file. */
#define BUFFSIZE 1000000
[code]....
View 2 Replies
View Related
Jan 10, 2014
I'm doing an exercise that prints all input lines that are longer than 80 characters. I rather not use any libraries so I decided to write my own function that counts characters to use it in my main program. However when integrate things my function returns zero all the time.
Here is my full code:
/* Exercise 1-17 Write a program to print all input lines that are longer than 80 characters */
#include<stdio.h>
/* Declarations*/
#define MAX_STRING_LEN 1000
int count_characters(char S1[]);
int main() {
[Code] .....
So I was trying to debug my count_characters() function and this is the code if I was to run it seperately:
Code:
#include <stdio.h>
/* counts character of a string*/
main() {
int nc = 0;
int c;
for (nc = 0; (c = getchar()) != '
'; ++nc);
printf("Number of characters = %d
", nc);
}
which works...
View 1 Replies
View Related
Nov 28, 2012
I have a file that contain different content, some lines inside that file looks like that :
Time : xx:xx:xx
Time : xx:xx:xx
So, I want to grab lines that start with "Time : " and put them inside a list<string> for later use. I am using windows so I don't know if the newline character is '
' or '
' also I don't want my grabed line contain any special character.
I have this code, but didn't work well because some special characters remain inside the string.
Code:
string buf;
list<string> ls;
ifstream read("test.txt", ios_base::binary);
while(!read.eof())
{
getline(read,buf,'
[Code]...
View 1 Replies
View Related
Aug 1, 2013
I am trying to reuse some code from my Visual C++ 2005. I am using CArchive to ReadString the first line of a file into another string. However, I am seeing squares where there should be spaces when I view it in the debugger.
Here's the code:
if( cfSAP.GetStatus(csRegExtractFileRemote, cfsStatus)) {
if( !cfSAP.Open( csRegExtractFileRemote, CFile::modeRead, &ef ) ) {
cout<<"FAILED
"<<endl;
ef.ReportError();
[Code] ....
I am not able to read the lines due to this bug ,
This is normal text file contains two lines of information like this
0234568374C186-M-233545 SHAFT MATNUMBER1
0234564565C153-C-349578 BRACKET MATNUMBER2
View 4 Replies
View Related
Jul 28, 2013
I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines.
I have created rectangle region for each line and trying to move the line.
When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen.
How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC.
View 4 Replies
View Related
Oct 15, 2013
I am trying to print a specific line from a textfile
e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity
Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8
I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?
Code:
string temDescription;
ofstream fout;
int curLine = 0;
[Code].....
View 1 Replies
View Related
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
Feb 3, 2014
I am facing a programming logic problem. I want to draw radius sized lines from centre of circle to the circle boundary.
My code is:
int x1, y1, x2, y2, i, r, old_xc,old_yc, x,y;
int xc, yc;
x1=170;
y1=300;
x2=70;
y2=400;
pDC->Ellipse(x1,y1,x2,y2);
[Code] .....
The lines are touching the circle boudary at only start while the rest of lines are smaller and the shape is a triangle instead of a pie slice.
View 8 Replies
View Related
Jul 28, 2013
I'm trying to put an if-else statement in a do-while loop and when I put the correct answer in the if statement I get that error. Here's the program:
#include <iostream>
using namespace std;
int main() {
int answer;
char repeat;
[Code] .....
View 5 Replies
View Related
Apr 9, 2014
I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?
View 2 Replies
View Related
Dec 26, 2014
Im working on my project for college and i want to know how to add sth similar to a chronometer for user to see how much time have passed while entering some characters using cin.getline function.
View 2 Replies
View Related
Mar 4, 2013
What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line. The goal of the parsing program is to interpret the symbols (characters), if there are any per each position, on the 5 lines of text in order to output the actual data that the group of symbols represents.
My question for is this: Is there anything special from a C++ environment that should go in to something like this outside of using standard stuff like the math associated with the search algorithm that has to happen here? The symbols are located in a file, so I know I have to include "iostream" and a few other headers. But outside of header inclusions and the code necessary to iterate and streamline the search and interpretation process, am I missing anything special that I couldn't otherwise find through simple google searches?
View 6 Replies
View Related
Feb 24, 2015
I'm pretty new to C++ and I'm on Binary Trees in "Jumping into C++"! I've just created a DLL project on Code::Blocks, and I cannot get it to build and run: "You must select a host application to "run" a library..." is the message that I'm getting when I run the main code file. It's had no changes to it (except for a few extra, unnecessary line feeds), and it's the file which Code::Blocks generates on a DLL project.
View 13 Replies
View Related
Nov 20, 2014
I was trying to make boost's serialization use less bytes, and I stumbled upon this, which removes the big debugging symbols:
strip --strip-debug
or
strip -w -K '!*serialization*'
This seems like a working command on msys, but how to implement this into code blocks.
View 1 Replies
View Related
Jun 9, 2013
This has happened before, when I try to run a code it will say "blah.exe has stopped working" and I would have to change the code in some way to make it work.
View 1 Replies
View Related
Apr 30, 2013
I'm using Code Blocks but for some reason it doesn't process alt symbols. You know... alt symbols are like this: ☺♫↓☻♪♥↕. Code Blocks says that they're "invalid characters". Is there any attatchments or mods so Code Blocks can process them or will changing the settings?
View 1 Replies
View Related
Mar 20, 2014
so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?
Code:
int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);
[Code]...
View 6 Replies
View Related
Jul 6, 2014
Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '