C :: Count Lines In Input And Display Output In Terminal When Program Executed After Compilation

Feb 4, 2013

Code:

#include <stdio.h>
main() {
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '')
++n1;
printf("%d", n1);
}

I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.

View 4 Replies


ADVERTISEMENT

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 :: Program Count Number Of Lines Of Read Text File

Jan 25, 2013

I have a .txt file that contains, together with a few characters, columns of values that I want to save in different files like is written in the program (file 1, file2, file3 - a with x, b with y, c with z). The pattern of the source text file is like this:

known_vector frame1 151 65 0 frame2 151.000763 64.538582 0.563737
known_vector frame1 152 65 0 frame2 152.000702 64.542488 0.560822
known_vector frame1 153 65 0 frame2 153.000671 64.546150 0.558089

Until now I could manage to split the files, but the output gives me only zeros. First the program count the number of lines of the read text file, then it should display the desired columns of double values in three other .txt files.I've got for the three .txt files columns like this:

0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

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 :: Program To Count Number Of Lines In Text File And Reverse Contents

Jan 25, 2015

C program to count the number of lines in a text file and reverse the contents in the file to write in an output file.

ex :
input
one
two
three

output:
three
two
one

View 6 Replies View Related

C++ :: Read User Input - Count And Display Vowels

Sep 26, 2012

I'm trying to code a program to read the user's input and have it:

-count vowels
-stop counting vowels after '.' or '?' (ie. abcdjwef is 1 a, 1 e; while fje.fwdfeiii is just 1 e)
-closes when ENTER is pressed after a '.' or '?' is found (ie. closes after 'abacds. ENTER' as well as 'as.fefsdf ENTER')
-display the number of vowels

Is there any way to do this with only 'cin >> userInput' and a while loop checking for punctuation?

View 1 Replies View Related

C++ :: Read Story From Input File / Separate Words And Output Lines On Which The Word Occurs

Feb 21, 2014

I have program that is supposed to read in a story from an input file and separate the words and output the lines on which the word occurs. It needs to read in another input file that has a list of words (1 per line) to ignore. i.e. skip them when running through the story. This is what I have so far, I've changed multiple things trying to get it running....

#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include"split.h"

[Code] .....

View 1 Replies View Related

C/C++ :: Program That Count Empty Line And Display Whole File

Jan 6, 2015

I am new in c programming. I want to write a function that will count the empty line of the file and display the content.

/* ***************************
** creator: firstprint *
******************************/

#include <stdio.h>
/* function that will identify if line is empty or not */
is_empty(char *buffer) {
while(isspace(*buffer)) buffer++;
if(*buffer==0x00) return 1;

[Code] ....

View 4 Replies View Related

C++ :: Input A Name Horizontal And Display Output In Vertical Position

Feb 9, 2013

Program that input a name horizontal and display the name in vertical position using looping any kind of looping?

EX.
INPUT:Enter A name:John
OUTPUT:
J
O
H
N

View 3 Replies View Related

C :: Program That Counts Letters Of 3 Lines Of Input From User

May 26, 2013

So I am writing a program that counts the letters of 3 lines of input from the user. I am using a 3 x 80 character array as the "notepad". Upper and lower case characters are incremented on the same counter array.

Code:

/*Letters in a string*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void countAlphabet(char *);
/*Character counting array*/
int alphabet[26] = {0};

[Code]...

View 3 Replies View Related

Visual C++ :: Program That Count From 1 To 12 And Print Count And Its Square For Each Count

Dec 16, 2014

4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.

4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.

4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.

View 2 Replies View Related

C++ :: Cumulative GPA - Program Fails To Display Output

Dec 9, 2013

How do i display the output ? This program only saves the output to "gpa.txt" I want it to also display the output to cmd.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
const int SIZE = 10;

[Code] ....

View 1 Replies View Related

C++ :: Program Breaks If Copy Stuff With Multiple Lines Into Console - Clearing Input Buffer

Apr 16, 2014

Using cin.sync() works great so far, but my program still breaks if you copy something with multiple lines into the console.

string test = "";
while(true) {
cin.sync();
getline(cin, test );
cout << endl << "test: " << test << endl;
}

However, if you were to copy this:
1
2
3

and paste it into the program, the output would be1
2
3

test: 1
test: 2

And if you press enter one more time:1
2
3

test: 1
test: 2
test: 3

The 3 finally pops out.

View 2 Replies View Related

C :: How To Count Lines In Dat File Using Fscanf

Sep 15, 2013

I need a way to count lines in a .dat file using fscanf. I must use a regex to check that the characters in the file are alphanumeric. In essence I need to count the ' ' character. I know fscanf ignores this character. I need to exit if it detects anything other than alphanumeric with the digit that is "problem" along with the line number. My .dat file is:

Code:
howard jim dave
joe
(
Maggie My fileCheck.c is: Code: #include "main.h"
int fileCheck(FILE *fp)
{
int ret_val;
int line_count = 0;
char file[BUFF];

[Code]...

The output I am getting is:

Code:
file opened Digit: ( is not an alphanumeric character on line: 5 Program will exit! File closed As you can see, the character "(" is not on the 5th line but the 3rd. It is the 5th "string."

I also wanted to show the regex I am using.

Code:
#define to_find "^[a-zA-Z0-9]+$"

How this can be accomplished?

View 5 Replies View Related

C Sharp :: How To Count Number Of Lines In XML

Feb 4, 2013

Below is the response XML my programmer is getting from business service -

<Data>
<Maintain>
  <AssetList>
     <AssetDetails>
          <AssetDescriptor> 
             <ns1:ParentProductCat category="ABC">ABC</ns1:ParentProductCat

[code].....

In above XMl if you check the ParentProductCat is prefixed with ns1:,ns2:,ns3:....

My XSLT code only checkes for the ParentProductCat but since it is prefixed with "ns*:" (* is integer) it fails to find it. So that in C# code replace function is used to replace ns*: a for loop is used for this and it goes until 1000

But now my response crossed the 1000 mark and this time the XML contains total 14500 lines.So I want to replace all ns:*

For this I want to count the number of lines present in the XML so that the for loop will run until that line number. how to do that?

View 2 Replies View Related

C/C++ :: Program Runs Into Error After Input Display

May 16, 2014

The code is supposed to display the total and averages of the data as well, but cuts off due to an error in the code. The code should also:

1)Print checks for all employees, one per page, sorted by lastname. The first check number, 100, is to be read from a company data file (see requirement 4). The border of each check is important and should not be omitted.

2)Convert the net pay to a text string for each check printed.

3)Print a reference code on each check. The reference code is obtained by combining the first letter of the lastname with all the consonants remaining after removing all vowels (a,e,i,o,u).

4)Use the same employee data found in assignment 2. Use company data, obtained from a text file, for each check printed:

Spoiler

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef short BOOLEAN;
typedef char STR15[15 + 1];
typedef char STR10[10 + 1];
typedef struct PayRecord

[Code] .....

View 14 Replies View Related

C/C++ :: Can't Get Basic Input / Output Program To Work

Feb 29, 2012

im trying to write a program that prompts the user to enter three numbers and then prints them vertically (each on one line), first forward and then reversed. this is how the design should look:

enter three numbers: 1 43 54

your numbers fowards:

1
43
54

your numbers backwards:

54
43
1

this is what i have thus far when it comes to code....
   
#include <stdio>  
int main (void) {
// local declarations 
int a;
int b;
int c

[code].....

View 1 Replies View Related

C++ :: Make Terminal Screen Bigger In NCurses Program?

Jun 29, 2013

I wanted to make the terminal screen bigger in my NCurses program. Let's say if the defaults are 25 LINES and 80 COLS, I want to set them to 40 LINES and 120 COLS.

I've tried resizing all windows, but that did not work, because the actual terminal (console) was not resized. Then I found functions resizeterm and newterm, but they did not work. As far as my understanding goes resizeterm only updates NCurses information with the current configuration, while the window itself is not actually modified.

NCurses man page wrote:The function resizeterm resizes the standard and current windows to the specified dimensions

If I haven't made myself clear ( I sometimes make a mess of things... ), another example would be that I want my program to be fullscreen when I start it. Is this possible? It should be, I found a fullscreen NCurses program once, but the code was too confusing for me to understand.

Having read about things like SIGWINCH, I assume you must define a method for resizing the terminal screen yourself, I don't know where to start?

View 11 Replies View Related

C/C++ :: Program To Allow User Input And Output Perfect Number

Mar 11, 2014

The problem that I am having is that , the program outputs numbers that are perfect numbers and im not sure where i can add a statement to make it so that if it isn't a perfect number it doesn't output...

#include<iostream>// allows user input/output
#include<conio.h>
#include<fstream>//data file / result file
#include<iomanip>
#include<cmath> // math function
#define in_file "data.txt"
#define out_file "result.txt"

[Code] ....

View 3 Replies View Related

C++ :: Voter Program - Input Names And Votes / Output Who Won The Vote

Apr 27, 2013

In my class we were supposed to write a program from the book that inputted the names and votes and the program is supposed to spit out who won the vote. I did this then while i was reading the assignment from the instructor I noticed he wanted the information inputted from a TXT file instead of manually inputting it. I cannot seem to get it to work....

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define N 5
char names[N][20];
float votes[N];

[Code] ....

here is the txt file

Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800

View 2 Replies View Related

C++ :: Program Will Echo Letter (User Input) And Output Name Of The Day Of Week

Oct 21, 2012

Write a C++ program that does the following:

Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.

When the user enters a character, the program will echo the letter and output the name of the day of the week.

Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.

So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.

Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?

View 4 Replies View Related

C/C++ :: Function Output For Three Lines

Nov 23, 2014

I am doing a written lab in my programming class in which we must write the output for three lines in a function. However, when I enter the code in my compiler I only get error messages. I was just wondering what the outputs under snap, crackle and pop should be and why.

#include <iostream>
using namespace std;
void snap (int i, int j);
void crackle (int &a, int &B)/>;
void pop (int &e, int f);
int main () {
int i = 1, j = 2;

[Code] .....

View 4 Replies View Related

C++ :: Effect On Output Of Program Of Different Numbers Input To Int Data Type Named

Mar 2, 2014

// this program gives random number output
#include <iostream>
#include <cstdlib>// contains function protype for rand
#include <iomanip>// for setw
using namespace std;

[code]....

what is the effect on output of program of different numbers input to the int data type named seed*/

View 1 Replies View Related

C++ :: Display Lines Between User Designated Points With Circles At Each Point

Jan 22, 2015

I'm trying to write a code that displays lines between user designated points with circles at each point, but I can't get the lines to display! I'm at a loss on what to do and need fresh eyes on the subject.

#include <iostream>
#include "graph1.h"
using namespace std;
//Function Prototypes Follow
void getNoPoints(int* no_points);
void getPoints(int* x, int* y,int no_points);
void drawPolyLine(int* x, int* y, int no_points,int objects[]);

[Code] ....

I imagine the error is in this segment:

int i=0;
for (i = 0; i < no_points;) {
objects[i] = drawLine(x[i],y[i],x[++i],y[++i],1);
setColor(objects[i],255,255,0);
}

View 1 Replies View Related

C :: Shows Lines Of Running In Output With Gdb Without Stopping

Feb 24, 2013

I run the program with gdb , i searched but find nothing about how i could run gdb , that shows what line of code is running constantly (i rather it also shows value of the variable on each line if it's possible ) without stopping (i mean i don't want to enter "step" every time , i just need to run the program with debugger and shows line of the code is running (without need to enter step each time by myself)is it possible? if yes , what command is needed to start gdb for this purpose?

P.S: for this purpose if i have to set breakpint i will. but even i rather not set breakpoint , i rather gdb while running the program shows what line is now executing (rather with the value of variabels).

View 4 Replies View Related

C++ :: Display Count Of Positive And Negative And Zero Entered

Aug 18, 2014

Write a program to enter the number till 100 till the user want and at the end it should display the count of positive and negative and zero entered.

View 8 Replies View Related







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