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


ADVERTISEMENT

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 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 :: 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/C++ :: Loading File With Fscanf?

Apr 21, 2015

I am trying to copy the stats from the save file "lol.txt" to main. I posted what the contents of the file below, but for some reason the I get for output jiberish and I cannot seem to figure out why.

#define _CRT_SECURE_NO_WARNINGS
#define MAX_NAME 31
#include <stdio.h>
int main(void){
char sName[MAX_NAME];

[Code] .....

View 5 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 :: Phone Book Saving To File And Retrieving

Jul 14, 2013

I am supposed to make this phone book save to a file and then be able to retrieve it.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Phonebook_Contacts
{
char FirstName[20];
char LastName[20];
char PhoneNumber[20];
} phone;
}

[code]....

View 4 Replies View Related

C :: Read From A File Containing Serial Of Number

Jun 2, 2014

I want to read a file who contain a serial of number like in this example : +200,-100,+400,+200,-200 and the sign is very important for the rest of the program so i should save those signed numbers in an array or a struct that i can define with a boolen variable if it's + i give it 1 else if it's - it'll be 0

I wrote a basic file's code reader but i don't think there is a solution on it

Code:
void read_file(char *fil1){
FILE *f;
int ch[500];
f=fopen(fil1,"rt");
if(f==NULL)

[Code] .....

View 1 Replies View Related

C++ :: Read One Number At A Time From Int File?

Sep 15, 2013

I have a file called example.txt . In that file, the int 123456 is stored. How can I read one independent number from that int? Lets say, I have an int variable called "Weight." How do I set weight equal to the number 1 from the int 123456 in the file?

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

C++ :: Store Address Of Customer In Char Variable - How To Read A Line With Spaces

Oct 10, 2014

I want to store the address of a customer (with spaces) in a char variable (say cadd). First I tried to use "cin", as we know it reads until it sees any whitespace. So it reads only first word before a white space. So, I used "getline()" function, it will work. But when I used it, It did'nt wait for the I/P (it skipped it).

char cadd[20];
std::cout<<"Enter Customer Address:
";
std::cin>>cadd;
std::cout<<"Enter Customer Address:
";
std::cin.getline(cadd,20);

View 3 Replies View Related

C++ :: Encrypting MAC Address To 4 Digit Number

Apr 4, 2014

I want to encrypt Mac address to 4 digit number which can be decrypted to original MAC address.

View 9 Replies View Related

C :: Fscanf Data And Delimiters

Dec 7, 2013

How would I fscanf this piece of data?

Delimiter is --> :
VS1234567890654327:Rob Fordfirst:001:200
VS1234567890654312:Steven Harper:200:010

Code:
while(3==fscanf(filename, "????", &string[size], &name[size], &number1[size], &number2[size])) {
//printf("%s - %s - %.3d - %.3d", string[size], name[size], number1[size], number2[size]));
size++;
}

View 6 Replies View Related

C :: Fscanf Data To Arrays

Apr 17, 2014

I am a very fresh c programme user, in fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code? When I printf the array it always ends up with random numbers.

Here is my code:

#include <stdio.h>#define SIZE 2
#define count 2
int main()
{
[code]....

and the file i am trying to read from :

Code:
1, 2, 3, 4
5, 6, 7, 8
8, 9, 10, 11

I am trying to scan a list of 3 by 4 numbers and the 4 numbers of each column to the 4 different arrays, so if I read from the data above, i get an array with numbers 1,5,8; another with 2,6,9 and so on. Is it how its done in my code?

View 2 Replies View Related

C/C++ :: Use Fscanf To Obtain A Set Of 14 Or So Strings Per Line?

Feb 25, 2012

I am trying to use fscanf to obtain a set of 14 or so strings per line, in a line where there are around 80 or so different sets of strings. I only need the first 14 and whenever I call scan f it starts at column 209 as opposed to column 1 where it should. Here's a sample of the code:

FILE *d;
d=fopen("t.dat","rb");
where a, n are all strings.
fscanf(d,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s",&a,&b,&c,..(etc)..,&n);

A sample of the Input file looks like this:
USB270.15385-29.63146 270.153847 -29.631455 2.966699e+03 -9.99 1.300391e+03 -9.99 -9.99 A-A-- 6.787463e+01 -9.99 1.555773e+02 -9.99 -9.99 10100 | ----- ------ ------ ------ | 0.373 13.554 12.928 12.670 AAA | ----- -------- - -------- - -------- - -------- - | --- ---------- - ---------- - --------- - --------- - --------- - ---------- -

View 7 Replies View Related

C :: Program With Fscanf Keeps Crashing - Using Eclipse Kepler

Oct 13, 2013

So this program I have to make keeps spitting out an error report when I try and run it. I am using eclipse C kepler.

The file it is supposed to read has the following text;

R1 N001 N003 20
R2 N002 N001 5
R3 N001 0 10
R4 N002 N003 10
R5 N003 N000 5
I1 0 N002 10

View 2 Replies View Related

C :: Fscanf - Segmentation Fault For Larger Project

Apr 19, 2013

I added this snippet of code to a larger project I use to read some numbers in from a file, but for some reason I'm getting a segmentation fault.

Code:
printf("starting main
");
FILE *cutoffs;
double cut1=0, cut2=0, cut3=0;
printf("trying to open file

The cutoffs.in file looks something like

Code: 3.475 3.875 4.025

I ran the gdb debugger, so I know it is occurring at that fscanf; however, it doesn't give any other details (to be honest I don't have much experience with debuggers :x) ..The values are being put into an array. Before I just had numbers initialized in the array by hand, but need to have 20 different runs of this code with different numbers each time...

View 2 Replies View Related

C++ :: Fscanf And Verifying Correct Input Length

Jan 24, 2012

I am trying to make a program that will read in input in the following format:

| ...text... || ...more text... || ...still more text...|

i.e. every bit of "text" that gets read in is bracketed on either side by the "|" character.

The buffer that i read them into can be of a maximum length of 101 (100 characters plus a terminating null character); this is how I am currently reading in the input:

char readString [100 + 1];
while ( fscanf(infile, "|%1000[^|]|", readString) ){
/*... manipulate readString ...*/
}

How might I design this program so that, should any of the text appearing between the "|" characters exceed 100 in length, it exits and returns a warning?

View 4 Replies View Related

C :: Fscanf Data To Array - It Always Ends Up With Random Numbers

Apr 16, 2014

I am a very fresh c programme user, and need to fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code?

When I printf the array it always ends up with random numbers. Below is my programme which is just designed to read a doc and print it back out, as well as the text doc it is designed to read.

View 3 Replies View Related

C :: How To Get Memory Address Of A File In Hard Disk

Sep 12, 2013

I made a text file. I can do all File I/O functions in c. no problem! except that "I want to get the memory address of the beginning of that File", so that I can access each character of the file by incrementing memory address.

View 1 Replies View Related

Visual C++ :: Address Of Entry Point In Binary File?

Dec 28, 2013

How can I find/calculate the address of the entry point for an exe binary file using its PE32 optional header?

I have added a picture, where it says (file addr) thats the address I want to know how to calculate

View 2 Replies View Related

C/C++ :: Adding Two Phone Agendas Together

Apr 4, 2015

I got this problem where I need to create a phone agenda where every name coresponds to a phone number. I decided to create this as a 2 dimensional string array.

But what I do not know how to do is:

I need to create 2 agendas(created in main(ag1 and ag2)) and then add them together to create one big agenda that contains the members of ag1 and ag2.

#include "stdafx.h"
using namespace std;
class Agenda{
string date[20][20];
public:
Agenda();
void afisare();

[Code] ....

View 1 Replies View Related

C/C++ :: Better Way To Parse And Format Phone Numbers?

Sep 3, 2014

I'm a student. I've complete an exercise where the goal is to parse some user input to output phone numbers using EXACTLY this style (not including the quotes): "1-888-8888".

Some rules that I've set for my parser are,

1) the phone number can be mixed in with other text, e.g. "My number is 38888888" or "1asdfk8888888" and

2) the first number found must be a valid calling code (1-9).

I wanted the parser to be flexible. Is this nesting too deep?

std::string format_phone_num(std::string &s) {
std::string formatted_num = "";
bool call_code_found = false;
short num_count = 0;
for (unsigned int i = 0; i < s.length(); i++)

[code].....

View 4 Replies View Related

C Sharp :: How To Remove Ads And Add More Space (Windows Phone)

Aug 18, 2013

I have made a new Windows Phone App and I would like there to be two versions: one without ads (79p) and one with ads (free). I have sorted out everything expect one issue. I collapse the advert if the app is in the full version but the rest of the page stays the same. How do I move the 'content panel' after the advert is collapsed?

View 1 Replies View Related

C :: Read Contents Of A File Using Low I/O Read Statements

May 15, 2013

I want to read the contents of a file block (512 bytes) by block using low I/O read statements. Each record is 64 bytes long and has a pre-defined structure. The first 4 bytes are an unsigned integer; the next 20 bytes are ascii text, etc.

I have a buffer which I can access with buf[0] to buf[63] to read the first record and then buf[64] to buf[127] for the second, etc. However, I was wondering how to map a record so that I can refer to an integer as an integer and a float as float, etc. I can't create a struct and move the 64 bytes to it, as I will have alllignment/padding problems.

What is the standard way to deal with records in C?

View 5 Replies View Related







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