C++ :: Read Phone Number Into Array And Can't Use String Data Type

Jan 13, 2013

I have an assignment where I need to read in a phone number into any array and I can't use the string data type. Assuming I need to use the getline function, how do I do this? I'm guessing it's with the cstring or .c_str() functions? I don't know.

View 4 Replies


ADVERTISEMENT

C/C++ :: Read Name / Phone Number And Address From A File - How To Use Fscanf

Nov 28, 2014

I am trying to read the name, phone number and address from a file ... Here is the code but it doesn't work and i don't know where is the problem ...

#include <stdio.h>
#include <stdlib.h>
struct PhoneBook{
        char name[50];
        int phoneNumber;
        char address[50];

[Code] ....

And here is the contents of the file:
jack 01014 jgd

Moh 02925 Tyeu

When I run it on dev c++, a message appear saying that the prog has stopped working and no output appears. I want to put the name in user[n].name, the phone number in user[n].phoneNumber and the address in user[n].address

View 1 Replies View Related

C++ :: What Data Type That Will Read In Letters And Numbers Form Fstream

Sep 11, 2013

What data_type will read in a string of letters mixed with numbers using fstream :);

View 1 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C :: User Can Input Phone Number In Any Of Formats

Jun 18, 2013

I'm having a bit issue with ispunct in my function. The user can input a phone number in any of the formats below:

4147778888
(414)7778888
(414)777-8888

The program will only print out:

41447778888

What I am trying to do is accept any integer and parentheses. If the user inputs anything else, the program will display an error message. Right now, parentheses displays an error which is obvious but I'm wondering if there is a way I can allow a parentheses to be entered but not any other symbol. ex: . , : ; " '

Code:
void getPhoneNum(){
// Local Declarations
char string[14];
char* tokPtr;

[Code] ....

View 6 Replies View Related

C :: Generate Words From User Input (Phone Number)

Aug 13, 2013

The basic idea of this exercise is to generate words from a user-input, seven-digit number(a phone number). The code runs, but for some reason, I can't get it to print the numbers into the file.

Code:
/*Write a program that will generate a word based on a randomly generated, seven-digit number. there should be 2187 possible words. Avoid "phone numbers" that begin with 0 or 1*/

#include<stdio.h>
#define PHONE 7
void wordGenerator(int number[]);
void wordGenerator(int number[]) {
//loop counters for each digit in the number

[Code] ....

View 3 Replies View Related

C++ :: Intellisensor Not Recognizing String Data Type

Apr 26, 2014

So Im working on my semester prject for my programming class. It is to make a roulette game. And Im working on getting my table set up but the intellisensor in my Visual Studio seems to not be working and recognizing the string variable type. Its not changing to blue when I enter it.

This program is a roulette simulation, designed to be used for online gambling.

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <string>
#include <ctime>
using namespace std;
//Function Prototypes
void welcome();
double getBalance();

[Code] .....

When I run the program it gives me an error as well sometimes. This one: Unhandled exception at 0x0f681f68 (msvcp100d.dll) in Roulette Final Project.exe: 0xC0000005: Access violation reading location 0x8bb59d35.

Which opens another tab named "iosfwd" and points to this bit of code:

static int_type __CLRCALL_OR_CDECL to_int_type(const _Elem& _Ch)
{// convert character to metacharacter
return ((unsigned char)_Ch);
}

View 5 Replies View Related

C :: Write A Program That Converts Alphanumeric Phone Number Into Numeric Form

Mar 6, 2015

i m learning c programming and i m stuck with this program for some reason.Write a program that converts alphanumeric phone number into numeric form:

O/P:
Enter phone number: CALLAT 2255288
here is the code i have written:
/** compilers shows no error **/
and O/P I get is
Enter phone number: CALLAT
/**blank space***/

Code:

#include<stdio.h>
int main(void)
{
char ch;
printf("Enter phone number:");
ch=getchar();
}

[code]....

View 4 Replies View Related

C++ :: Convert String Variable For The Year To Integer Data Type

May 12, 2014

My intent was to convert the string variable for the year to an integer data type. The code compiles but now cannot run on my system. I'm not sure what's going as to what the program is displaying.

Objective: Prompt the user for two years. Print all Comedy movies that were released between those two years.

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
struct Movie {
string name;

[Code] .....

View 2 Replies View Related

C++ :: Possible To Use Data Type Double Or Float For Array?

Mar 9, 2014

Can you use data type double or float for an array? ie

double n[];
or
float a;
float m[a];

My code wont accept me changing the data type..will on accept int data type. I get the following error when I try to change the array to double or float..

3310E:C++vector.cpp[Error] invalid types 'double [1000][double]' for array subscript

View 4 Replies View Related

C++ :: Storing File Data In Array With Structure Type?

Feb 20, 2015

I have a structure

struct Wine
{
string wineName;
int vintage;
int rating;
double price;
};

how can i store the file data below in an array with the structure type???

Dow Vintage Port ;2011;99;82
Mollydooker Shiraz Carnival of Love ;2012;95;75
Prats & Symington Douro Chryseia ;2011;97;55
Quinta do Vale Meão Douro ;2011;97;76
Leeuwin Chardonnay River Art Series ;2011;96;89

View 1 Replies View Related

C++ :: Initializing Array Of String Type In A Class

Apr 28, 2013

I want to use this array as part of my class. I have tried several different angles trying to get it to work but with out success. I have been checking to see if it works by simply using "cout << dayName[3];" It is printing nothing at all. What is the proper way to initialize this array of strings?

First I tried this:
const string dayName[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

then I tried this:
const string dayName[7];
dayName[0] = "Sunday";
dayName[1] = "Monday";
dayName[2] ="Tuesday";
dayName[3] ="Wednesday";
dayName[4] ="Thursday";
dayName[5] ="Friday";
dayName[6] ="Saturday";

My implemetation file code and my header file code is here (header first):

//dayType.h, the specification file for the class dayType
#include <iostream>
#include <string>
using namespace std;
class dayType{

[Code] .....

View 4 Replies View Related

C :: How To Make Array Of Structures For Basic Contact List In A Phone

Oct 17, 2013

So for class I have to make an array of structures for a basic contact list in a phone.

I understand the bones of the program and how to go about doing most of it but as far as arrays of structures go I am blind.
Code:

struct phone
{
char FirstName[16];
char LastName[16];
int Number[11];
};
struct phone numbers[friends]; //friends is a variable assigned by the user What I am a bit confused about is say the user enters 30 as how many friends they have. How would I assign a value to the 3rd struct for LastName?

View 3 Replies View Related

C++ :: How To Read Data From TXT File Into Array

Feb 25, 2013

I wanna read a txt file like this
1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 .....
and fill the array P[i][j] with the data.

I try to use

if (myfile.is_open()) {
//for (int i = 0; i < 1; i++)
//{
getline (myfile,DMArray[0]);
cout << DMArray[i] << endl;
//}
myfile.close();
}

But this read the data into a string. How should i do with this string. Besides I know the dimension of the data I am reading.

View 1 Replies View Related

C++ :: Create Main Function With One Dimension Dynamic Array With Float Data Type

Dec 4, 2013

I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?

View 6 Replies View Related

C++ :: Read A File Into 2D Array And Display Data

Nov 15, 2014

I am currently working on a problem where I read a file into a 2D array, and display data. If you saw my code earlier, this is the same problem, but I am now further along.

The file (90 characters) looks like this:
S
R
R
S
R
R
R
R
S
S
....

The "R" resembles rainy days, the "S" resembles sunny days, and the "C" resembles cloudy days. There are 90 characters in the file. The first 30 are for the month of June, the next 30 are for the month of July, and the last 30 are for the month of August. The 31st day of the months are NOT included.

I read the data into a 3 x 30 array, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the number of days in each month.

Now I need to create a function that creates a report and displays, for each month AND for the whole 3 month period:
1) The number of rainy days
2) The number of cloudy days
3) The number of sunny days
4) Which of the 3 months had the largest number of rainy days

Here is my code so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MONTHS = 3;//Number of months

[Code] .....

There are no compiling errors, but I am not getting the data I want. My rCount and cCount variables end up being 0, and my sCount variable is 90.

View 4 Replies View Related

C++ :: Read From A File And Place Data Into Array

May 3, 2014

Assume you want to read from a file and place the data from the file into an array. The array can hold 10 integers. The file may contain any number of integers with 1 integer per line. Fill in the missing loop test condition so that we will read from the file until either end of file occurs or the array is full. Note we are using cin to read from the file since input redirection is being used.

cin >> temp;
arrayIndex = 0;
while ( _____________________________________) {
array[arrayIndex] = temp;
arrayIndex++;
cin >> temp;
}

View 2 Replies View Related

C++ :: Unable To Read Data File From Two Dimensional Array

Apr 27, 2014

I am new to C++ and I am having an issue reading in a 2 Dimensional array from a data file. I am very close to reading it in perfectly except for one issue, the loop is ignoring the first value from the data file.

This is the code I have so far:

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <functional>
#include <conio.h>
#include <iomanip>
#include <string>
#include <fstream>

[Code]...

This is the values from the data file:

300 450 500 210
510 600 750 400
627 100 420 430
530 621 730 530
200 050 058 200
100 082 920 290

When the Program shows my array it comes up as:

450 500 210 510
600 750 400 627
100 420 430 530
621 730 530 200
050 058 200 100
082 920 290 0

Every array location is moved up one, like the program just completely ignored the 300 at the beginning.

View 1 Replies View Related

C++ :: Sort Data From Text File Into Array As Its Being Read?

Feb 12, 2013

I am suppose to make a program that reads in data from a text file (integers only) and sorts them as it inserts them into an array of size 10. I did this using an insertion sort, which worked great. But now I am being told that I need the function has to read ALL of the numbers in the text file, not just the first 10, and I am not allowed to store them THEN sort, it has to be sorted as being stored.

This is what I have for sorting first 10

void sortArray(int iArray[])
{
string fileName = "";
fstream inFile;
int tmp = 0;

[Code]....

View 3 Replies View Related

C/C++ :: Read BMP Image Data Into Multidimensional Array Of Structures

Apr 8, 2014

I am trying to read the information from a .bmp file into my program while dynamically allocating memory for all of it. So I defined the structures for the headers and for a pixel, and then I have to read each pixel into a multi-dimensional array of pixels. I am completely new to structures, and definitely new to pointers combined with structures. I will have to use a filter with the information later, but right now I just want to read everything in correctly. The array of pixels will be two-dimensional -- the width by the height of the image, I guess.

Here's my code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *inFile, *outFile;
typedef struct

[Code] ....

View 4 Replies View Related

C++ :: Read Data From File Then Make It Into Array Of Structures And Print Afterwards

May 13, 2012

I am trying to read from a data file that has input as :

12.0, 11, 123
14.0, 12.1, 3

And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.

Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_INPUT 1000
int n =0;
int i = 0;
typedef struct {
double x[MAX_INPUT];

[Code] .....

The program when run gives the following output:

Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
ProjectB.c: In function "main":
ProjectB.c:59: error: incompatible type for argument 1 of "print_array"

View 1 Replies View Related

C/C++ :: Read Integers Into Array / Sort Numbers And Print Out Occurrence Of Each Number

Apr 6, 2014

My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.

void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */

[Code] .....

View 6 Replies View Related

C++ :: Using Array To Enter Number Of Users And Their Data?

Dec 10, 2014

I have a small program to calculate the value of salary. I want to user to be able to enter more than one user using array and finally calculates the average salary of all users.

Here is the code

Code:
#include <iostream>#include <conio.h>
using namespace std;
int main() {
const int months=3;
double net_pay;
string EmpName;

[Code].....

View 2 Replies View Related

C++ :: Access To Data Of Array While Have Its Name As String

Jul 31, 2013

The problem is as following. First, I have 21 arrays named: integer abee1, abee2, ... , abee20 and myarray all with the same dimension of [51][4]. Next, in a loop of 20 circles, I fill myarray with random integers then copy it into abee1-20 (each one per iteration). Then, for each array (abee1-20), I want to calculate sum of all numbers in second column as cost of that array and store it in the a new array called arrayCosts[20][2] ( char arrayName, int arrayCost)- the name of array in the arrayName column and cost of that array into arrayCost column . After that, I want to sort arrayName based on the cost and extract the 3 top array with lowest cost. I know that I should do a search in the array to find these three. Finally, copy these three into 3 new array called elite1, elite2, elite3.I do not know what to do.

1-The following code is for making the sting name of abee1-20 in string made in each step of the loop.

for ( cc = 1 ; cc < 20; cc++)
{ string String = static_cast<ostringstream*>( &( ostringstream () << cc) )->str();
string array_name = "abee" + String;

I want to use array_name (for example in the first loop which array_name is “abee1” ) for reaching the abee1 (which is a filled array) after dong a search in the array called “arrayCosts”. This search retrieves the name of array but it is string and I want to have the array with the same name.

View 2 Replies View Related

C++ :: Input Number As String In Array

Jul 23, 2013

I need to ask the user to input a number, and then put the number in a string array. so for example if the size of the number was 4: example 1200

i would make him put the number like that

for (i1=0; i1 < 4; i1++)
cin >> Num1[i1];
where Num1[] is a char array type. yes and it works.

But my question is what if I do not know how many numbers will the user put, how do i extract the size of the total characters existing in a number?

View 5 Replies View Related

C :: Create New Data Type Data Declared As Int

Feb 1, 2015

I'm trying to create a new data type Data declared as int. What comes up to my mind is to create a structure like

Code:

typedef struct Data {
int number;
} Data;

but when I need to use the data I need to go through the structure. Is this a good way to declare a new data type?

View 2 Replies View Related







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