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
ADVERTISEMENT
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
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
View Related
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
Aug 28, 2013
The below code is taken from open source filezilla project
(FileZilla_3.7.3_srcfilezilla-3.7.3srcinterfacebookmarks_dialog.cpp)
Code:
#include <filezilla.h>
#include "bookmarks_dialog.h"
#include "sitemanager.h"
#include "ipcmutex.h"
#include "themeprovider.h"
#include "xmlfunctions.h"
BEGIN_EVENT_TABLE(CNewBookmarkDialog, wxDialogEx)
EVT_BUTTON(XRCID("wxID_OK"), CNewBookmarkDialog::OnOK)
EVT_BUTTON(XRCID("ID_BROWSE"), CNewBookmarkDialog::OnBrowse)
END_EVENT_TABLE()
I'm unable to understand what are these lines after the #include. They don't end in semicolons. Looks very much like function calls.
Are BEGIN_EVENT_TABLE, EVT_BUTTON and END_EVENT_TABLE function calls? Function calls should end with semicolons right?
View 5 Replies
View Related
Jan 14, 2014
I need to write a code (in C99). The programe receives an input number (integer) 'n' and then a matrix sized n*n (matrix[n][n]), all numbers are integers. We're supposed to define the matrix's size with malloc. Now the program needs to sort the lines of the matrix (the number in each line), in a single function (!) this way:
even line index (0,2,4,6...): from small to big.
odds line index (1,3,5...): from big to small.
and then print it.
*note: first line is indexed 0, second line is 1, etc.
I was thinking to sort it with bubblesort function with the following if:
if(i%2==1)
do odds sorting.
else
do even sorting.
when i is the index of the row.
my problem is defining the malloc and how do I send the matrix to sorting.If needed I will attach my current (not so good (completly awful)) code and functions as well as an example of what the prog. supposed to do.
View 13 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
Mar 17, 2013
In my code the cout phrase is supposed to give me an angle in degrees. no matter which 2 points i enter in, it always outputs the angle between them to be 57. This is because the acos value of 0 in degrees is 57. The program compiles without error.
Here is the code:
/*
Synopsis: This program reads in the coordinates of two 2D vectors and outputs the angle between the vectors in degrees.
*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// function prototypes
// ENTER FUNCTION PROTOTYPE FOR normalize() HERE.
void normalize(double & x, double & y);
[Code] .....
View 2 Replies
View Related
Jan 21, 2015
I am currently trying to understand why this example for using an array as an argument in a function has a different result than what the lecture notes say it should be.
So supposedly sum should return with the value 28, but I get 27 no matter what. I also am not very good at reading and understanding what exactly the order of operations for this function are.
Code:
#include <iostream>
using namespace std;
int sum(const int array[], const int length) {
long sum = 0;
for (int i = 0; i < length; sum += array[++i]);
return sum;
[Code] ....
View 3 Replies
View Related
Nov 16, 2013
Finally got to functions. Made a simple one that adds two numbers:
Code: int add(int a, int b){
cout<<"a+b=";
return a+b;
}
It refuses to give an output unless I use cout.
If I just call the function like so: "add(12, 24);", shouldn't it print out a+b=36? It only prints out "a+b=", unless I use "cout<<" ahead of the call.
My simple question is why does it need cout ahead of the call? Shouldn't "return" do its job and print out the number?
View 2 Replies
View Related
Mar 27, 2013
I have written a function that takes in a positive decimal and returns its Binary equivalent; however, the output always adds an additional zero to the binary. What could I do to get rid of it?
If the number is 7, it outputs 0111 instead of 111.
Code:
#include <stdio.h>
void Dec(int n) {
if(n > 0)
Dec(n/2);
printf("%i", n%2);
[Code] ....
View 2 Replies
View Related
Apr 25, 2013
I want to create a function that will accept input from the user and return the input, to be used for further calculation. I know how to accept and return with integers as parameters , but how do i do it with arrays?
Suppose there is an array of numbers arr[]. Now, i want a function that accepts the input from the user, and return the array for further manipulation.
For example, if the array is arr[5], then i should call a function and accept the values from the user. Then, i should return the imputed values and print the same. How can i do this.
View 3 Replies
View Related
Dec 10, 2014
I am having an issue with my Call Function to output data. The compiler doesn't like the Call function to output data.
#pragma once
namespace WindowsFormsApplication1 {
using namespace System;
[Code].....
View 1 Replies
View Related
Oct 11, 2013
I have to convert a binary value from an input file (the name of which is given by the user) and then convert the binary to decimal value and print that in an output file.
Right now it is compiling just fine with no error messages, but when I run the program, it doesn't end or print to the output file.
Here is my code at the moment:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
[Code].....
View 2 Replies
View Related
Aug 20, 2014
I am trying to implement own strcpy function, but no output is being printed.
#include<stdio.h>
#include<string.h>
void strcpy_own(char dest[], char src[], int len);
int main() {
char src[15]="jeevan", dest[15];
[Code] ....
View 3 Replies
View Related
Jan 13, 2013
#include<iostream>
#include <ncurses.h>
#include <curses.h>
using namespace std;
int main() {
initscr(); // Initalise the ncurses library
[Code] ....
It prints table upto 10 really wel but after 10 all tables get scatterd .
View 1 Replies
View Related
Mar 28, 2013
I have this simple code here:
Code:
#include <iostream>
int multiply (double x, double y) {
double result = x*y;
return (result);
[Code] ....
I get the answer 5.94 (which is what I'm looking for). I can't work out why the first example is not outputting a decimal number. I have set the variables as a double so I just can't see why this is not working for me.
View 1 Replies
View Related
Feb 28, 2013
What does the following nested loop output ?
count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}
View 9 Replies
View Related
Aug 10, 2014
Taken from Accelerated C++ book, I modified those code to use getline() instead of std::cin >> only to find out that the output has extra line. Why is that so?
#include <iostream>
#include <string>
int main() {
std::cout << "What is your name?" << std::endl;
std::string name;
[Code] .....
What is your name?
Naruto
*****************
* *
* Hello, Naruto
*
* *
*****************
Notice one asterisk after the greeting where it should be in the same line as the greeting.
View 4 Replies
View Related
Feb 12, 2013
So I am writing this code that analyzes a file called "analysis.txt" and prints out in an ouput file (called "report.txt") the results of the analysis, i.e.,(the frequency of all alphabet letters present in the file).
I am having trouble with outputing on the file2.
here is what I have:
Code:
#include<iostream>
#include<fstream>
using namespace std;
ifstream file1;
[Code]....
I tried to lose the "<<" after the file 2, but it's still giving me an error. how to output a void function on a text file?
View 14 Replies
View Related
Oct 22, 2014
I am trying to find a way to put a getSmallest function in here so that it will output smallest integer entered. If it is just an arbitrary amount of #'s and I don't know what will be entered I am confused. Both on how to do it and how to link my function to my loop.
Code:
/* Prompts user and gets integer numbers from keyboard, one number at a time. Ends program when 99999 entered. and displays various results.
Written by:
Date: 10/20/14
*/
#include <stdio.h>
#include <stdlib.h>
[Code] .....
Could I take this and just replace all variables a, b, and c with getNumber, where would I link/declare smallest?
Code:
/* ==================== smallest ======================
This function returns the smallest of 3 integers.
Pre given 3 integers
Post the smallest integer returned
*/
int smallest (int a, int b, int c) {
[Code] ......
View 1 Replies
View Related
May 10, 2014
Instead of this:
#include <iostream>
struct Object {
int size; // Want to avoid this because size is (almost always) constant
Object (int s): size(s) {} // for every Object subtype.
[Code] ....
I want this:
#include <iostream>
struct Object {
virtual int getSize() const = 0;
};
struct Block: Object {
int getSize() const {return 5;} // always 5, except once in a blue moon it may change
[Code] ....
The Decorator Pattern works (getSize() can then return 6) but it is a poor choice for my program because it will cause more problems (due to many containers holding its old address, among other things. Any way to achieve this without any change of address, and without creating new storage somewhere, either inside the class or outside the class (too much responsibility to follow that stored value for the rest of the program just for this rare change, and creating a data member uses up too much memory for the many, many Block instances)?
View 5 Replies
View Related
Jun 12, 2014
Basically I'm supposed to use a while loop to generate a random number and use a switch statement to output the appropriate information. I feel like I'm missing a few things that are very simple.
The errors are:
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4700: uninitialized local variable 'randomNumber' used
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
int i = 0;
unsigned int randomNumber;
[Code] .....
View 2 Replies
View Related
Nov 5, 2013
I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.
void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)
[Code] ....
The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:
output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);
How to get the numbers of the main function to show up with the stars of the previous function.
View 6 Replies
View Related
Jul 11, 2012
I'm trying to write a debug functions for my application so I can see all the values I like to. My goal is it looks like this:
Code:
void Debug(std::message, ...)
So that I can call it like this:
Code:
Debug("Error: %i, %i", 34, 35);
How I can work with %i, or if there are better solutions. This is what I've so far (not much), just a basic idea:
Code:
void Debug( std::string message, ...) {
va_list list;
va_start(list, message);
??? va_arg(list, ?? );
va_end(list);
// here message should contain everything and be ready for output ?
cout << message << endl;
}
View 3 Replies
View Related
Oct 27, 2013
I am working on a project and decided to try something simple before I start adding items. I am calling a function from main and that function has a file pointer.
Here is my main.cpp
Code: #include <cstdio>
#include <string>
#include <iostream>
#include "main.h"
extern FILE *fp;
using namespace std;
int main(int argc, char *argv[])
[code]....
Here is the function:
Code:
#include <string>
#include <cstdio>
#include <iostream>
#include "main.h"
[Code] ....
My test file consists of several characters and digits. Nothing special and I at this point in time do not have any type of formatting that needs to be adhered to. I am simply wanting to read the file character by character and print it out. When I run the program, I get this symbol:
Code: If I use a printf statement, such as:
Code: printf("%s
", nextChar);
I get a segmentation fault.
My main.h Code:
#ifndef MAIN_H
#define MAIN_H
void scanner(FILE *);
//char getChar(FILE *);
#endif and lastly my scanner.h Code: #ifndef SCANNER_H
#define SCANNER_H
FILE *fp;
#endif
View 6 Replies
View Related