Program not writing to another fileHow to get a specific memory address using Cproblem with flushing input stream CHow do I use extern to share variables between source files?ftell error after the first call to freadfopen in c does not work without running in debug modeSegmentation fault error using strtok() and strcmp()Read csv file of strings to 2D char* array using Cwho can please explain to me why this atoi command works and howCan't run printf() on a null-terminated stringInserting text into a txt file
When does it become illegal to exchange bitcoin for cash?
My players like to search everything. What do they find?
Why is quantum gravity non-renormalizable?
What is the point of using the kunai?
SQL Server Ignoring Instance name when using port number of different instance
To “Er” Is Human
Confusion in understanding the behavior of inductor in RL circuit with DC source
Searching for single buildings in QGIS
Why are symbols not written in words?
I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again
How to idiomatically express the idea "if you can cheat without being caught, do it"
Avoiding repetition when using the "snprintf idiom" to write text
What does this Pokemon Trainer mean by saying the player is "SHELLOS"?
What type of education should I select in this form?
Square wave to sawtooth wave using two BJT
Can I hire several veteran soldiers to accompany me?
What is this fluorinated organic substance?
What is the meaning of ゴト in the context of 鮎
How far can gerrymandering go?
Is this house-rule removing the increased effect of cantrips at higher character levels balanced?
Sentences with no verb, but an ablative
What happened to the Apollo 1 rocket?
What caused the flashes in the video footage of Chernobyl?
Can you run PoE Cat6 alongside standard Cat6 cables?
Program not writing to another file
How to get a specific memory address using Cproblem with flushing input stream CHow do I use extern to share variables between source files?ftell error after the first call to freadfopen in c does not work without running in debug modeSegmentation fault error using strtok() and strcmp()Read csv file of strings to 2D char* array using Cwho can please explain to me why this atoi command works and howCan't run printf() on a null-terminated stringInserting text into a txt file
This program is supposed to take a user's input on an area code, search a separate file that has a bunch of phone numbers listed in the txt file, and a function search is supposed to test the phone number with the input area code to see if it matches. The main
function then writes the phone numbers into a separate txt file.
I have tried to use strstr
but I figured the best way to test it is to use strtok
and strcmp
, which is what I have now.
/* This program will search phone_numbers.txt for phone numbers. It will create a new file with unique area codes in each file.
(Ex: 813 area codes will go into 813_phone_numbers file).
--Brandon Yates
*/
#include <stdio.h>
#include <string.h>
int search(char *area_code, char *phone_number);
int read_line(char *str, int n);
int main()
char area_code[3];
char phone_number[101];
char *file_name;
FILE *number_file;
FILE *new_file;
printf("Enter the area code: ");
scanf("%s", &area_code);
//area_code = ∾
read_line(area_code, 2);
number_file = fopen("phone_numbers.txt", "r");
if (number_file == NULL)
printf("Cannot open file.n");
return -1;
new_file = fopen("dest_file.txt", "a");
if (new_file == NULL)
printf("Cannot open file.n");
return -1;
//scat = strcat(area_code, file_name);
while (fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file))
if (search(area_code, phone_number))
fputs(phone_number, new_file);
fclose(number_file);
fclose(new_file);
printf("Output: encoded words are written to file %s", file_name);
return 0;
/*
Search function determines if a phone number in the input file
matches the area code.
Search function returns 1 if the phone number matches the area code
and 0 otherwise.
*/
int search(char *area_code, char *phone_number)
printf("testing");
char *pch;
pch = strtok(phone_number, "()");
while (pch != NULL)
if (strcmp(area_code, phone_number) == 0)
return 1;
pch = strtok(NULL, "()");
return 0;
int read_line(char *str, int n)
int ch;
int i = 0;
while ((ch = getchar()) != 'n')
if (i < n)
*str++= ch;
i++;
*str = ''; /* terminates string */
return i; /* number of characters stored */
I expect the phone numbers to be written to a text file, but I end up with an empty file. What is going on?
c tokenize
add a comment |
This program is supposed to take a user's input on an area code, search a separate file that has a bunch of phone numbers listed in the txt file, and a function search is supposed to test the phone number with the input area code to see if it matches. The main
function then writes the phone numbers into a separate txt file.
I have tried to use strstr
but I figured the best way to test it is to use strtok
and strcmp
, which is what I have now.
/* This program will search phone_numbers.txt for phone numbers. It will create a new file with unique area codes in each file.
(Ex: 813 area codes will go into 813_phone_numbers file).
--Brandon Yates
*/
#include <stdio.h>
#include <string.h>
int search(char *area_code, char *phone_number);
int read_line(char *str, int n);
int main()
char area_code[3];
char phone_number[101];
char *file_name;
FILE *number_file;
FILE *new_file;
printf("Enter the area code: ");
scanf("%s", &area_code);
//area_code = ∾
read_line(area_code, 2);
number_file = fopen("phone_numbers.txt", "r");
if (number_file == NULL)
printf("Cannot open file.n");
return -1;
new_file = fopen("dest_file.txt", "a");
if (new_file == NULL)
printf("Cannot open file.n");
return -1;
//scat = strcat(area_code, file_name);
while (fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file))
if (search(area_code, phone_number))
fputs(phone_number, new_file);
fclose(number_file);
fclose(new_file);
printf("Output: encoded words are written to file %s", file_name);
return 0;
/*
Search function determines if a phone number in the input file
matches the area code.
Search function returns 1 if the phone number matches the area code
and 0 otherwise.
*/
int search(char *area_code, char *phone_number)
printf("testing");
char *pch;
pch = strtok(phone_number, "()");
while (pch != NULL)
if (strcmp(area_code, phone_number) == 0)
return 1;
pch = strtok(NULL, "()");
return 0;
int read_line(char *str, int n)
int ch;
int i = 0;
while ((ch = getchar()) != 'n')
if (i < n)
*str++= ch;
i++;
*str = ''; /* terminates string */
return i; /* number of characters stored */
I expect the phone numbers to be written to a text file, but I end up with an empty file. What is going on?
c tokenize
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
You should show a few lines ofphone_numbers.txt
and what you enter as input.
– Bodo
Mar 25 at 17:31
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
scanf
andread_line
aren't working with well with each other; this results inarea_code
containing garbage values. Replacescanf
andread_line
withfgets
.
– fbynite
Mar 25 at 18:24
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44
add a comment |
This program is supposed to take a user's input on an area code, search a separate file that has a bunch of phone numbers listed in the txt file, and a function search is supposed to test the phone number with the input area code to see if it matches. The main
function then writes the phone numbers into a separate txt file.
I have tried to use strstr
but I figured the best way to test it is to use strtok
and strcmp
, which is what I have now.
/* This program will search phone_numbers.txt for phone numbers. It will create a new file with unique area codes in each file.
(Ex: 813 area codes will go into 813_phone_numbers file).
--Brandon Yates
*/
#include <stdio.h>
#include <string.h>
int search(char *area_code, char *phone_number);
int read_line(char *str, int n);
int main()
char area_code[3];
char phone_number[101];
char *file_name;
FILE *number_file;
FILE *new_file;
printf("Enter the area code: ");
scanf("%s", &area_code);
//area_code = ∾
read_line(area_code, 2);
number_file = fopen("phone_numbers.txt", "r");
if (number_file == NULL)
printf("Cannot open file.n");
return -1;
new_file = fopen("dest_file.txt", "a");
if (new_file == NULL)
printf("Cannot open file.n");
return -1;
//scat = strcat(area_code, file_name);
while (fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file))
if (search(area_code, phone_number))
fputs(phone_number, new_file);
fclose(number_file);
fclose(new_file);
printf("Output: encoded words are written to file %s", file_name);
return 0;
/*
Search function determines if a phone number in the input file
matches the area code.
Search function returns 1 if the phone number matches the area code
and 0 otherwise.
*/
int search(char *area_code, char *phone_number)
printf("testing");
char *pch;
pch = strtok(phone_number, "()");
while (pch != NULL)
if (strcmp(area_code, phone_number) == 0)
return 1;
pch = strtok(NULL, "()");
return 0;
int read_line(char *str, int n)
int ch;
int i = 0;
while ((ch = getchar()) != 'n')
if (i < n)
*str++= ch;
i++;
*str = ''; /* terminates string */
return i; /* number of characters stored */
I expect the phone numbers to be written to a text file, but I end up with an empty file. What is going on?
c tokenize
This program is supposed to take a user's input on an area code, search a separate file that has a bunch of phone numbers listed in the txt file, and a function search is supposed to test the phone number with the input area code to see if it matches. The main
function then writes the phone numbers into a separate txt file.
I have tried to use strstr
but I figured the best way to test it is to use strtok
and strcmp
, which is what I have now.
/* This program will search phone_numbers.txt for phone numbers. It will create a new file with unique area codes in each file.
(Ex: 813 area codes will go into 813_phone_numbers file).
--Brandon Yates
*/
#include <stdio.h>
#include <string.h>
int search(char *area_code, char *phone_number);
int read_line(char *str, int n);
int main()
char area_code[3];
char phone_number[101];
char *file_name;
FILE *number_file;
FILE *new_file;
printf("Enter the area code: ");
scanf("%s", &area_code);
//area_code = ∾
read_line(area_code, 2);
number_file = fopen("phone_numbers.txt", "r");
if (number_file == NULL)
printf("Cannot open file.n");
return -1;
new_file = fopen("dest_file.txt", "a");
if (new_file == NULL)
printf("Cannot open file.n");
return -1;
//scat = strcat(area_code, file_name);
while (fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file))
if (search(area_code, phone_number))
fputs(phone_number, new_file);
fclose(number_file);
fclose(new_file);
printf("Output: encoded words are written to file %s", file_name);
return 0;
/*
Search function determines if a phone number in the input file
matches the area code.
Search function returns 1 if the phone number matches the area code
and 0 otherwise.
*/
int search(char *area_code, char *phone_number)
printf("testing");
char *pch;
pch = strtok(phone_number, "()");
while (pch != NULL)
if (strcmp(area_code, phone_number) == 0)
return 1;
pch = strtok(NULL, "()");
return 0;
int read_line(char *str, int n)
int ch;
int i = 0;
while ((ch = getchar()) != 'n')
if (i < n)
*str++= ch;
i++;
*str = ''; /* terminates string */
return i; /* number of characters stored */
I expect the phone numbers to be written to a text file, but I end up with an empty file. What is going on?
c tokenize
c tokenize
edited Mar 25 at 20:30
chqrlie
67.2k9 gold badges58 silver badges114 bronze badges
67.2k9 gold badges58 silver badges114 bronze badges
asked Mar 25 at 17:27
cr0wncr0wn
264 bronze badges
264 bronze badges
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
You should show a few lines ofphone_numbers.txt
and what you enter as input.
– Bodo
Mar 25 at 17:31
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
scanf
andread_line
aren't working with well with each other; this results inarea_code
containing garbage values. Replacescanf
andread_line
withfgets
.
– fbynite
Mar 25 at 18:24
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44
add a comment |
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
You should show a few lines ofphone_numbers.txt
and what you enter as input.
– Bodo
Mar 25 at 17:31
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
scanf
andread_line
aren't working with well with each other; this results inarea_code
containing garbage values. Replacescanf
andread_line
withfgets
.
– fbynite
Mar 25 at 18:24
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
You should show a few lines of
phone_numbers.txt
and what you enter as input.– Bodo
Mar 25 at 17:31
You should show a few lines of
phone_numbers.txt
and what you enter as input.– Bodo
Mar 25 at 17:31
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
scanf
and read_line
aren't working with well with each other; this results in area_code
containing garbage values. Replace scanf
and read_line
with fgets
.– fbynite
Mar 25 at 18:24
scanf
and read_line
aren't working with well with each other; this results in area_code
containing garbage values. Replace scanf
and read_line
with fgets
.– fbynite
Mar 25 at 18:24
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44
add a comment |
1 Answer
1
active
oldest
votes
There are multiple problems in your program:
the array
area_code
is too small: it can only accommodate strings of 0, 1 or 2 characters. Since you do not tellscanf()
to limit the input to a maximum of 2 characters, the area code typed by the user fills the array andscanf
modifies memory beyond the end of the array, causing undefined behavior.you read user input twice into the
area_code
array. The first time withscanf()
, which may cause undefined behavior, but leaves the newline pending in standard input, and then withread_line()
which reads the pending newline and makesarea_code
an empty string...Make
area_code
larger and either tellscanf()
about the maximum number of characters to store there or just useread_line()
:char area_code[10];
...
if (scanf("%9s", area_code) != 1)
return 1;Note also that
fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file)
is redundant:fgets()
will returnNULL
on error and/or end of file, no need to perform redundant tests.The test in
search
is incorrect:if (strcmp(area_code, phone_number) == 0)
you should instead compare the token witharea_code
:if (strcmp(area_code, pch) == 0)
read_line
also has a potential problem: its argument is the maximum number of characters to read, which is different from the argument tofgets()
which is the size of the destination array. This is confusing and might cause bugs later if the function is givensizeof area_code
for the size argument.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343419%2fprogram-not-writing-to-another-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are multiple problems in your program:
the array
area_code
is too small: it can only accommodate strings of 0, 1 or 2 characters. Since you do not tellscanf()
to limit the input to a maximum of 2 characters, the area code typed by the user fills the array andscanf
modifies memory beyond the end of the array, causing undefined behavior.you read user input twice into the
area_code
array. The first time withscanf()
, which may cause undefined behavior, but leaves the newline pending in standard input, and then withread_line()
which reads the pending newline and makesarea_code
an empty string...Make
area_code
larger and either tellscanf()
about the maximum number of characters to store there or just useread_line()
:char area_code[10];
...
if (scanf("%9s", area_code) != 1)
return 1;Note also that
fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file)
is redundant:fgets()
will returnNULL
on error and/or end of file, no need to perform redundant tests.The test in
search
is incorrect:if (strcmp(area_code, phone_number) == 0)
you should instead compare the token witharea_code
:if (strcmp(area_code, pch) == 0)
read_line
also has a potential problem: its argument is the maximum number of characters to read, which is different from the argument tofgets()
which is the size of the destination array. This is confusing and might cause bugs later if the function is givensizeof area_code
for the size argument.
add a comment |
There are multiple problems in your program:
the array
area_code
is too small: it can only accommodate strings of 0, 1 or 2 characters. Since you do not tellscanf()
to limit the input to a maximum of 2 characters, the area code typed by the user fills the array andscanf
modifies memory beyond the end of the array, causing undefined behavior.you read user input twice into the
area_code
array. The first time withscanf()
, which may cause undefined behavior, but leaves the newline pending in standard input, and then withread_line()
which reads the pending newline and makesarea_code
an empty string...Make
area_code
larger and either tellscanf()
about the maximum number of characters to store there or just useread_line()
:char area_code[10];
...
if (scanf("%9s", area_code) != 1)
return 1;Note also that
fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file)
is redundant:fgets()
will returnNULL
on error and/or end of file, no need to perform redundant tests.The test in
search
is incorrect:if (strcmp(area_code, phone_number) == 0)
you should instead compare the token witharea_code
:if (strcmp(area_code, pch) == 0)
read_line
also has a potential problem: its argument is the maximum number of characters to read, which is different from the argument tofgets()
which is the size of the destination array. This is confusing and might cause bugs later if the function is givensizeof area_code
for the size argument.
add a comment |
There are multiple problems in your program:
the array
area_code
is too small: it can only accommodate strings of 0, 1 or 2 characters. Since you do not tellscanf()
to limit the input to a maximum of 2 characters, the area code typed by the user fills the array andscanf
modifies memory beyond the end of the array, causing undefined behavior.you read user input twice into the
area_code
array. The first time withscanf()
, which may cause undefined behavior, but leaves the newline pending in standard input, and then withread_line()
which reads the pending newline and makesarea_code
an empty string...Make
area_code
larger and either tellscanf()
about the maximum number of characters to store there or just useread_line()
:char area_code[10];
...
if (scanf("%9s", area_code) != 1)
return 1;Note also that
fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file)
is redundant:fgets()
will returnNULL
on error and/or end of file, no need to perform redundant tests.The test in
search
is incorrect:if (strcmp(area_code, phone_number) == 0)
you should instead compare the token witharea_code
:if (strcmp(area_code, pch) == 0)
read_line
also has a potential problem: its argument is the maximum number of characters to read, which is different from the argument tofgets()
which is the size of the destination array. This is confusing and might cause bugs later if the function is givensizeof area_code
for the size argument.
There are multiple problems in your program:
the array
area_code
is too small: it can only accommodate strings of 0, 1 or 2 characters. Since you do not tellscanf()
to limit the input to a maximum of 2 characters, the area code typed by the user fills the array andscanf
modifies memory beyond the end of the array, causing undefined behavior.you read user input twice into the
area_code
array. The first time withscanf()
, which may cause undefined behavior, but leaves the newline pending in standard input, and then withread_line()
which reads the pending newline and makesarea_code
an empty string...Make
area_code
larger and either tellscanf()
about the maximum number of characters to store there or just useread_line()
:char area_code[10];
...
if (scanf("%9s", area_code) != 1)
return 1;Note also that
fgets(phone_number, sizeof(phone_number), number_file) != NULL && !feof(number_file) && !ferror(number_file)
is redundant:fgets()
will returnNULL
on error and/or end of file, no need to perform redundant tests.The test in
search
is incorrect:if (strcmp(area_code, phone_number) == 0)
you should instead compare the token witharea_code
:if (strcmp(area_code, pch) == 0)
read_line
also has a potential problem: its argument is the maximum number of characters to read, which is different from the argument tofgets()
which is the size of the destination array. This is confusing and might cause bugs later if the function is givensizeof area_code
for the size argument.
edited Mar 25 at 20:48
answered Mar 25 at 20:37
chqrliechqrlie
67.2k9 gold badges58 silver badges114 bronze badges
67.2k9 gold badges58 silver badges114 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343419%2fprogram-not-writing-to-another-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is your input? you have a lot of code here. when you debug it, which function is failing to perform as expected?
– MFisherKDX
Mar 25 at 17:29
You should show a few lines of
phone_numbers.txt
and what you enter as input.– Bodo
Mar 25 at 17:31
Sorry, I did not realize that I did not post which was causing the error. It actually prints all the phone numbers now, it just doesn't test to see if the area code matches in the phone number. The function that is not working properly is search() I think specifically strcmp. I am on mobile and not sure how to edit it.
– cr0wn
Mar 25 at 17:49
scanf
andread_line
aren't working with well with each other; this results inarea_code
containing garbage values. Replacescanf
andread_line
withfgets
.– fbynite
Mar 25 at 18:24
In the USA, an area code is three digits. To store those in a string requires 4 bytes. You’re not allocating enough space. Where there’s one bug like that, there are usually several, if not many of them.
– Jonathan Leffler
Mar 25 at 18:44