Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:08+00:00 2026-06-14T12:24:08+00:00

I’m new to C and I’m working on trying to create the typical beginners

  • 0

I’m new to C and I’m working on trying to create the typical beginners phonebook app. I’ve seen a lot of different links on google that show examples of the phonebook app, but nothing that shows what I’m trying to accomplish. Basically what I’m wanting to do is create a structure that has first name, last name, and 2 phone numbers, then I want to create 2 different functions for each of those. For each variable in the structure I would have one that sets the input, and then another one that reads the input. This gives me 8 functions, but then I want to add three more functions, one for adding 11each new contract to the structure, one for deleting a contact and then one for viewing the phonebook. Right now I’m focusing on the adding function and viewing function. My issue is that I am getting very weird output.

#include<stdio.h>
#include<conio.h>

typedef struct friends_contact{
       char First_Name[10];
       char Last_Name[10];
       char home[15];
       char cell[15];

}fr;

void menu(fr*friends ,int* counter,int user_entry, char* nullStr,int i);
void setFirst(fr*,int *,int i);
char getFirst(fr*,int*,char*,int i);
void setLast(fr*friends, int* counter, int i);
char getLast(fr*friends ,int* counter,char *nullStr, int i);
void add_contact(fr*friends,int* counter,int i);
void show_contact(fr*friends ,int* counter,char *nullStr, int i);


int main()
{
  int user_entry=0;
  fr friends[5];
  int counter=0;
  char nullStr[21] = {"\0"}; 
  int i=0;

 menu(friends, &counter,user_entry,nullStr,i);
 getch();
 return 0;
}

void menu(fr*friends,int* counter,int user_entry,char *nullStr,int i)
{
  do{
  printf("Phone Book Application\n");
  printf("1) Add friend\n2) Delete friend\n3) Show a friend\n4) Show phonebook\n5)Exit);   
 scanf("%d", &user_entry);
  if(user_entry==1){

                    add_contact(friends,counter,i);
                    }
   if(user_entry==4){
                  show_contact(friends, counter,nullStr,i);
                   } 
   }while(user_entry!=5);                 
 }

 void setFirst(fr*friends, int* counter, int i)
{
 (*counter)++;
 printf("Enter a first name \n");
 scanf("%s",&friends[*counter-1].First_Name);
}
void setLast(fr*friends, int* counter, int i)
{
 (*counter)++;
 printf("Enter a first name \n");
 scanf("%s",&friends[*counter-1].Last_Name);
}
char getFirst(fr*friends ,int* counter,char *nullStr, int i)
{
     for(i=0; i<*counter; i++)
     {
        if (strcmp(nullStr, friends[i].First_Name) != 0) 
        {
           printf("%s\n", friends[i].First_Name);
        }
     }

return *friends[i].First_Name;
}

char getLast(fr*friends ,int* counter,char *nullStr, int i)
{
     for(i=0; i<*counter; i++)
     {
        if (strcmp(nullStr, friends[i].Last_Name) != 0) 
        {
           printf("%s\n", friends[i].Last_Name);
        }
     }

 return *friends[i].Last_Name;
}
void add_contact(fr*friends,int* counter,int i)
{ 
 setFirst(friends,counter,i); 
 setLast(friends,counter,i);
}    

void show_contact(fr*friends ,int* counter,char *nullStr, int i)
{
 getFirst(friends,counter,nullStr,i);
 getLast(friends,counter,nullStr,i);
}

Here is the output that I get now:

Enter a first name
john
Enter a first name
smith
Phone Book Application
1) Add friend
2) Delete friend
3) Show a friend
4) Show phone book
5) Exit

4
john
╝ ♠

smith

my results are equally as weird when i add another name to the list. Whats weird is I only started having these problems after I created the last name function. When I entered just first names it worked fine. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:24:09+00:00Added an answer on June 14, 2026 at 12:24 pm

    OK, I made some changes and I paste you the whole code (including the main)
    I got rid of the variable nullStr. When you want to see if a name is balnk you can use strlen(string) which gives you the size of that string. If the size is 0 it means the string is blank.

    Here is the code:

    # include< stdio.h >
    # include < string.h >

    typedef struct friends_contact{

      char First_Name[10];
       char Last_Name[10];
       char home[15];
       char cell[15];
    

    }fr;

    void menu(fr*friends ,int* counter,int user_entry,int i);
    void setFirst(fr*,int *,int i);
    char getFirst(fr*,int i);
    void setLast(fr*friends, int* counter, int i);
    char getLast(fr*friends , int i);
    void add_contact(fr*friends,int* counter,int i);
    void show_contact(fr*friends ,int* counter, int i);
    

    int main()
    {

    int user_entry=0;
    fr friends[5];
    int counter=0;
    int i=0;
    menu(friends, &counter,user_entry,i);
    return 0;
    

    }

    void menu(fr*friends,int* counter,int user_entry, int i)
    {

    do{

    printf("Phone Book Application\n");
    printf("1) Add friend\n2) Delete friend\n3) Show a friend\n
                   4) Show phonebook\n5)Exit");   
    

    scanf(“%d”, &user_entry);

    if(user_entry==1){
                add_contact(friends,counter,i);
                }
       if(user_entry==4){
              show_contact(friends, counter,i);
               } 
       }while(user_entry!=5);                 
    

    }

    void setFirst(fr*friends, int* counter, int i)
    {

        printf("Enter a first name \n");
        scanf("%s",friends[*counter].First_Name);
    

    }

    void setLast(fr*friends, int* counter, int i)
    {

        printf("Enter a first name \n");
        scanf("%s",friends[*counter].Last_Name);
    

    }

    void add_contact(fr*friends,int* counter,int i)
    {

        setFirst(friends,counter,i); 
        setLast(friends,counter,i);
        (*counter)++;
    

    }

    void show_contact(fr*friends ,int* counter, int i) {

    for( i = 0; i < *counter; i++)
    
      if (strlen(friends[i].First_Name) && strlen(friends[i].Last_Name) )
        {
    
                getFirst(friends, i);
                getLast(friends, i);
        }
    

    }

    char getFirst(fr*friends , int pos) {

       printf("%s ", friends[pos].First_Name);
       return *friends[pos].First_Name;
    

    }

    char getLast(fr*friends , int pos) {

          printf("%s\n", friends[pos].Last_Name);
          return *friends[pos].Last_Name;
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.