Commit 8f60c6dc authored by Ardavan_Roozkhosh's avatar Ardavan_Roozkhosh

c codes and executable files

parents
Pipeline #2742 failed with stages
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="PB" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/PB" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/PB" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
# depslib dependency file v1.0
1516698382 source:c:\users\ardavan\desktop\coding\phone book\pb\main.c
<stdio.h>
<stdlib.h>
<string.h>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="167" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct PhoneBook_Contacts
{
char FirstName[20];
char LastName[20];
char PhoneNumber[20];
} phone;
void AddEntry (phone * );
void DeleteEntry (phone * );
void PrintEntry (phone * );
int counter = 0;
int main (void)
{
phone *phonebook;
phonebook = (phone*) malloc(sizeof(phone)*1);
int iSelection = 0;
if (phonebook == NULL)
{
printf("Out of Memory. The program will now exit");
return 1;
}
else {}
while (iSelection <= 4)
{
printf("\n\tPhonebook Menu");
printf("\n\n\t(1).....> Add Contact");
printf("\n\t(2)-----> Delete Contact");
printf("\n\t(3).....> Display All Contacts");
printf("\n\t(4)-----> Exit The App");
printf("\n\nplease select your desired option ");
scanf("%d", &iSelection);
if (iSelection == 1)
{
AddEntry(phonebook);
}
if (iSelection == 2)
{
DeleteEntry (phonebook);
}
if (iSelection == 3)
{
PrintEntry(phonebook);
}
if (iSelection == 4)
{
printf("The Phonebook will now exit.");
system("cls");
free(phonebook);
return 0;
}
}
}
void AddEntry (phone * phonebook)
{
counter++;
realloc(phonebook, sizeof(phone));
printf("\nFirst Name: ");
scanf("%s", phonebook[counter-1].FirstName);
printf("Last Name: ");
scanf("%s", phonebook[counter-1].LastName);
printf("Phone Number :");
scanf("%s", phonebook[counter-1].PhoneNumber);
printf("\n\tContact successfully added to Phonebook\n");
}
void DeleteEntry (phone * phonebook)
{
int x = 0;
char deleteFirstName[20];
char deleteLastName[20];
char nullStr[20] = {"\0"};
printf("\nFirst name: ");
scanf("%s", deleteFirstName);
printf("Last name: ");
scanf("%s", deleteLastName);
for (x = 0; x < counter; x++)
{
if (strcmp(deleteFirstName, phonebook[x].FirstName) == 0)
{
for (x = 0; x < counter; x++)
{
if (strcmp(deleteLastName, phonebook[x].LastName) == 0)
{
strcpy(phonebook[x].FirstName, nullStr);
strcpy(phonebook[x].LastName, nullStr);
strcpy(phonebook[x].PhoneNumber, nullStr);
}
else
{
printf("Invalid Entry.");
}
}
}
}
counter--;
printf("Contact deleted from the phonebook.\n\n");
}
void PrintEntry (phone * phonebook)
{
int x = 0;
printf("\nPhonebook Contacts:\n\n ");
for( x = 0; x < counter; x++)
{
printf("\n(%d)\n", x+1);
printf("Name: %s %s\n", phonebook[x].FirstName, phonebook[x].LastName);
printf("Number: %s\n", phonebook[x].PhoneNumber);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment