Thread: Phonebook search without cs50.h library ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2023
    Posts
    13

    Phonebook search without cs50.h library ?

    Hi,

    Iam using different tutorials and sadly the lecture from Harvard on YT always uses a custom made "cs50.h" library which in the end just complicate things because I have to figure then things out myself, or is everyone using it ? I guess not so I obviously dont want to rely on it.

    Well here is a simple phonebook search, at least Iam not getting any errors anymore but the code also doesnt print out anything, any help would be appreciated.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    typedef struct
    {
        char name[20];
        char phone[20];
    }
    Phonebook;
    
    int main()
    {
    
    Phonebook people[2];
    
    Phonebook kevin;
    strcpy(kevin.name, "Kevin Schmidt");
    strcpy(kevin.phone, "827123");
    
    Phonebook maik;
    strcpy(maik.name, "Maik Mueller");
    strcpy(maik.phone, "67322188");
    
    char find[20];
    printf("Name to find ?: ");
    scanf("%s", find);
    
    for(int i = 0; i < 2; i++)
    {
        if(strcmp(people[i].name, find) == 0)
        printf("Found %s\n", people[i].phone);
    }
    return 0;
    }
    But maybe the whole thing is wrong I have no clue, thanks in advance as always :).
    Last edited by crusher152; 01-23-2024 at 11:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CS50 Caesar - Checking a string for digits
    By sclem in forum C Programming
    Replies: 3
    Last Post: 05-02-2020, 01:03 AM
  2. Harvard CS50 Online Help -- Mario Pyramid
    By mcavanaugh8 in forum C Programming
    Replies: 14
    Last Post: 02-01-2016, 02:40 PM
  3. Phonebook in C
    By alkurik in forum C Programming
    Replies: 4
    Last Post: 10-16-2014, 02:59 PM
  4. Code for CS50 functions?
    By VEN0M in forum C Programming
    Replies: 19
    Last Post: 07-25-2012, 11:53 AM
  5. Plz help me to include cs50.h and cs50.c into Code::Block
    By Huncowboy in forum C Programming
    Replies: 4
    Last Post: 03-09-2010, 10:05 AM

Tags for this Thread