C :: How To Print Everything Type Till Hit Enter Using POINTERS
Mar 5, 2013
I think I need to use
Code:
while(input[0]!='
'){
scanf("%s", input)
printf("%s", pointerhere);
}
basically we were asked to make a program that will print everything before the user hits the enter button. we cannot use fgets and we have to use pointers here.
not sure what exactly to do. We were told not to use fgets cause it's so easy and we need to incorporate pointers in this project..
View 8 Replies
ADVERTISEMENT
Feb 27, 2012
It seems to be going null. I can't get a null value, I want it to accept input till the user hits enter with no text typed. I've tried checking to see if the input is NULL, "", and " " all to no avail.
Code:
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstring>
using namespace std;
int main() {
string info = "";
[Code] ....
View 7 Replies
View Related
Nov 6, 2013
I want to do simple program to capture some 5 surnames of people(employees) - using array and pointers. Well I understand a bit of arrays and I know how to loop through.
How can achieve this? This holds the key to my understanding how pointers work and can be used with char or strings.
View 2 Replies
View Related
Jul 8, 2013
I've seen some threads that include the information about what data types one has to use usually to put a number of 12digit. But honestly speaking none of them works for me & it takes me a lot suffering about the data type. Even I've googled but I didn't get any specific result.
So, which data type I'd have to use to enter 12digit number.
I'm writing a code to find the largest prime factor of the number 600851475143
View 4 Replies
View Related
May 19, 2013
I have a program that uses class functions to enter and print out info. The problem is with the second function answers(). Here is the whole cpp file. In the answer function I need to use an exception to exit when its the end of an array. I could just be doing it wrong. I used try/catch originally but when I used it, it caught the exception but ended the whole program.
#include <iostream>
#include <cstdlib>
#include "answering_machine.h"
using namespace std;
void AnsweringMachine::init(){
numMessages = 0;
[Code] ......
View 6 Replies
View Related
Oct 27, 2013
Enter as many numbers as you want as long as the user doesn't type 'e' to exit.
Problem: When I enter a number, it works fine, but if I enter e then it'll go in an infinite loop since the letter is being stored in an int variable. How can I (when I press 'e') make it convert to a char to make it end the program?
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number or press e to exit:";
[Code] ....
Our class has just started c++ and we have not learned arrays and classes yet, so I'm guessing there is a way to do this without it? Or no?
View 2 Replies
View Related
Nov 22, 2014
I'm trying to enter an 'x' and 'y' coordinate on only one line separated by a comma. But I keep getting a syntax error. Here are the lines of code I'm using. This has to be simple. What am I doing wrong with this code?
Code:
cout<< "Please enter the x and the y coordinates of the first point,"<<endl;
cout<< "use a comma to separate them. " <<endl<<endl;
cin>> "You entered: " >>x1>>",">> y1 >>"for the first point" >>endl;
View 7 Replies
View Related
Oct 18, 2014
My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:
s – search
i – insert
a – append
d – delete
a – append
d – delete
r – replace
e – exit
s – search
This option will allow the user to search for a specified string in the worked-on string. If the string is
found, it will display the starting index (position) of the searched string in the worked-on string.
here is what i have so far.
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a_string[80];
[Code] .....
View 4 Replies
View Related
Sep 6, 2013
I want to give a try to "restrict" type-qualifier. I have looked for examples on google and I see the format is used: "int * restrict p";
However when I write this I get an error: "p is undeclared"
I am using GNU GCC Compiler with Code::Blocks.
How can I solve this problem. Is it possible me to adapt the compiler to C99 standarts, if I can, will it solve my problem?
View 13 Replies
View Related
Sep 4, 2014
Assume the user has already put in the number of students (hence my variables numStuds, which will most likely be irrelevant to my problem).
So suppose I have this:
void inputStudentInfo(string *names, int *movies, const int numStuds) {
for(int i =0; i < numStuds; i++) {
cout << "Enter student name: "; getline(cin, names[i]); read_string(names[i]);
[Code] ....
Then I have my data type checking function:
//Data-Type Checking for strings
string read_string(string Sname) {
while(!cin.good())
[Code] ....
I am getting errors. I know the problem I think is that I am trying to data type check for a string made up of pointers* with just a string but I don't know how I am supposed to check this?
View 2 Replies
View Related
Jan 29, 2015
I always have confusions while using pointers with functions both as arguments and as return type.
View 1 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Oct 7, 2014
here is a piece of my code:
while(T--)
{
std::vector<std::pair<int, int> > *dragon;
std::vector<std::pair<int, int> > *villager;
[Code]....
I now wish to print the elements of the vector. How do I do it?
View 2 Replies
View Related
Jan 23, 2013
Are there anyways to pause the loop until either LCONTROL or RCONTROL is pressed?
Are there alternatives to stopping LCONTROL and RCONTROL increasing or decreasing counter by a huge sum?
#include <iostream>
#include <windows.h>
#include <conio.h>
[Code].....
View 6 Replies
View Related
Dec 21, 2014
I'm in the middle of creating a ePOS for my uncle and so far I've created a database for it where it will create, update and delete records successfully.
My next step I would like to do is to create a printer till thing, but how do I connect my database to that ?
I can create a till but how do I do link my database with it? I followed this example here [URL] ....
View 5 Replies
View Related
Feb 8, 2013
I am using fin.peek() to read character from input file and saving each character into an array. Each line from the input has first name, last name, id number, and then 5-6 grades. Random spacing between each one.
input file example:
Adam Zeller 45678 80 87 60 90 88 100
David Young 34521 34 56 76 76 76 76
Carl Wilson 909034 90 90 90 49 39
my code for reading in and storing each character is this:
while(fin.peek() == ' ')
fin.get();
while(fin.peek() != ' ') ///// first name {
c = fin.get();
first[i] = c;
[Code] ....
The problem I am having is what sort of loop would go around this to read till end of file. I have tried eof. I have tried while(!fin.peek == ') and I have tried a couple of other methods. these methods resulted in a never ending loop execution.
View 1 Replies
View Related
Oct 22, 2013
I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.
Header File:
//safearrayType Header File
class safeArrayType {
public:
void print() const;
void insertAt(int location, const int& insertItem);
safeArrayType(int firstPlace=0, int maxPlace = 100);
[Code] ....
ResultsEnter the first bound of yourlist: -3(this was my input)
Enter the last bound of yourlist: 7(this was my input)
Press any key to continue...
View 1 Replies
View Related
Oct 23, 2013
So I made a simple letter guessing game a while ago and I want to make a simple edit. If the user does not press 'y' or 'n' and instead inputs an invalid letter, I want the printf's in the main function to loop until the user chooses to play or quit.
And I want the choices to show up again at the end of a game. Basically I want it to keep asking if the user wants to play until the user chooses to exit. Here's my code:
#include <stdio.h>
#include <time.h>
#define MAX_GUESSES 6
void Instructions ( ); //displays instructions, returns nothing
char Play ( ); //this functions plays one game, returns W if user wins & L if user runs out of tries
[Code] .....
I'm thinking of making a separate function (like Instructions and Play) ... But how would I link the user input back to the main function?
View 3 Replies
View Related
Jun 26, 2012
I have a event called dataTree_AfterSelect in which I have some code which I want to execute as atomic operation like this:
protected void dataTree_AfterSelect(event params)
{
code that should not be disturbed
}
What is happening now is, I am able to select another node of tree & in that case another execution of above function starts causing a garbled result.
What I want is, user should be able to click on tree node but execution of code block should only start after first execution is totally over.
View 4 Replies
View Related
Feb 28, 2014
I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried
Code:
int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
[code]...
the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..
View 4 Replies
View Related
May 21, 2013
I am a little confused while comparing char pointers to integer pointers. Here is the problem:
Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";
When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;
As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};
If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??
View 2 Replies
View Related
Apr 27, 2013
I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.
My current code is:
Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()
[Code]....
View 4 Replies
View Related
Dec 21, 2013
how to convert an element of int type of an array to char type?
View 2 Replies
View Related
Aug 31, 2014
I have a function like this:
template<typename T>
void f() {
//...
[Code]....
list contains, in order: A, B and C in any order, D, E
I am thinking it is possible with some clever template and polymorphism combos, but maybe not. As a last resort I know how to make it work by storing static type information in each class, but I'd like to avoid that if possible.
View 6 Replies
View Related
Nov 17, 2013
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
View 1 Replies
View Related
Sep 1, 2014
is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?
for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}
This is suppose to output
t=-3 *
t=-2 *
t=-1
.
.
.
View 2 Replies
View Related