Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created January 29, 2014 10:39
Show Gist options
  • Save kunishi/8685465 to your computer and use it in GitHub Desktop.
Save kunishi/8685465 to your computer and use it in GitHub Desktop.
Opu Experiments IB (C version), 1-6
/*
* File: arraymain.c
* Author: kunishi
*
* Created on 2008/11/25, 16:24
*/
#include <stdio.h>
#include <stdlib.h>
/* prototype declarations */
void add(char *, char *, int);
void delByName(char *);
void delByPhone(char *);
void delByNumber(int);
void findByName(char *);
void findByPhone(char *);
void findByNumber(int);
void printAll();
/*
*
*/
int main(int argc, char** argv) {
add("Takeo Kunishima", "080000000001", 1);
add("Kazumasa Yokota", "09011111111", 2);
printAll();
delByNumber(2);
printAll();
return (EXIT_SUCCESS);
}
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
struct person {
char name[256];
char phone[256];
int number;
} table[MAX];
/* basic functions */
void setEntry(char *n, char *p, int nu, int i)
{
strcpy(table[i].name, n);
strcpy(table[i].phone, p);
table[i].number = nu;
}
void printEntry(int i)
{
printf("%s|%s|%d\n", table[i].name, table[i].phone, table[i].number);
}
void add(char *n, char *p, int nu)
{
int i;
for (i = 0; i < MAX; i ++) {
if (strcmp(table[i].name, "") == 0) {
setEntry(n, p, nu, i);
break;
}
}
}
void delByName(char *n)
{
int i;
for (i = 0; i < MAX; i ++) {
if (strcmp(table[i].name, n) == 0) {
setEntry("", "", 0, i);
}
}
}
void delByPhone(char *p)
{
int i;
for (i = 0; i < MAX; i ++) {
if (strcmp(table[i].phone, p) == 0) {
setEntry("", "", 0, i);
}
}
}
void delByNumber(int nu)
{
int i;
for (i = 0; i < MAX; i ++) {
if (table[i].number == nu) {
setEntry("", "", 0, i);
}
}
}
void findByName(char *n)
{
int i;
for (i = 0; i < MAX; i ++) {
if (strcmp(table[i].name, n) == 0) {
printEntry(i);
}
}
}
void findByPhone(char *p)
{
int i;
for (i = 0; i < MAX; i ++) {
if (strcmp(table[i].phone, p) == 0) {
printEntry(i);
}
}
}
void findByNumber(int nu)
{
int i;
for (i = 0; i < MAX; i ++) {
if (table[i].number == nu) {
printEntry(i);
}
}
}
void printAll()
{
int i;
for (i = 0; i < MAX; i ++) {
printEntry(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment