Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char code[454][7];
char name [454][26];
char haveslist [454][11];
char wrapped [454][15];
char input [25];
char onbobbin[10];
char notonbobbin[14];
char all[4];
char have[6];
char donthave[12];
int i;
int f;
int h;
int r;
int len;
int arrays (int f, int *hPtr);
void edit (int i);
int main (int argc, const char * argv[]) {
int h;
for (r=0; r=100000; r++) {
fpurge(stdin);
char onbobbin[] = "on bobbin";
char notonbobbin[] = "not on bobbin";
char all[] = "all";
char have[] = "have";
char donthave[] = "don't have";
if (r!=0) {
printf("\n-----------\n");
}
printf("\nEnter code, name of color, \"on bobbin\", \"not on bobbin\", \"have\", \"don't have\" or \"all\" (q=quit):\n ");
fgets(input, 25, stdin);
len = strlen(input);
input[len - 1] = '\0';
if (*input == 'q') {
printf("Quitting.");
return (0);
}
else if (*input == '\0'){
f = 6;
}
else if (strcmp(input, onbobbin) == 0) {
f=1;
}
else if (strcmp(input, notonbobbin) == 0) {
f=2;
}
else if (strcmp(input, have) == 0) {
f=3;
}
else if (strcmp(input, donthave) == 0) {
f=4;
}
else if (strcmp(input, all) == 0) {
f=5;
}
else {f=0;}
arrays(f, &h);
if (h!=1 && f==0) {
edit(i);
}
else if (h == 1 && f==0) {
printf("Invalid entry.\n");
}
}
printf("-----------\n");
return 0;
}
int arrays (int f, int *hPtr) {
char compare5[] = "don't have";
FILE *namelist = fopen("../../namelist", "r+");
FILE *codelist = fopen("../../codelist", "r+");
FILE *wrappedlist = fopen("../../wrapped", "r+");
FILE *havelist = fopen("../../havelist", "r+");
fseek(namelist, 0, SEEK_SET);
fseek(codelist, 0, SEEK_SET);
fseek(wrappedlist, 0, SEEK_SET);
fseek(havelist, 0, SEEK_SET);
for (i=0; i<=453; i++) {
fgets(wrapped[i], 15, wrappedlist);
fgets(code[i], 7, codelist);
fgets(name[i], 26, namelist);
fgets(haveslist[i], 12, havelist);
len = strlen(code[i]);
code[i][len - 1] = '\0';
len = strlen(name[i]);
name[i][len - 1] = '\0';
len = strlen(wrapped[i]);
wrapped[i][len - 1] = '\0';
len = strlen(haveslist[i]);
haveslist[i][len - 1] = '\0';
if (f==1 && (strncmp(input, wrapped[i],1) == 0) && i!=454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],wrapped[i]);
}
else if (f==1 && (strncmp(input, wrapped[i],1) == 0) && i==454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i,f);
}
else if (f==2 && (strcmp(input, wrapped[i]) == 0) && i!=454){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
}
else if (f==2 && (strcmp(input, wrapped[i]) == 0) && i==454){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i, f);
}
else if (f==0 && (strcasecmp(input, code[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) != 0)) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
f=0;
*hPtr=0;
return(i, f);
}
else if (f==0 && (strcasecmp(input, code[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) == 0)) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
f=0;
*hPtr=0;
return(i, f);
}
else if (f==0 && (strcasecmp(input, name[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) != 0)) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
f=0;
*hPtr=0;
return(i, f);
}
else if (f==0 && (strcasecmp(input, name[i])==0) && (strncmp(haveslist[i], compare5, (size_t)1) == 0)) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
f=0;
*hPtr=0;
return(i, f);
}
else if(f==5 && i!=454 && strncmp(haveslist[i], compare5, (size_t)1)!=0){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
}
else if(f==5 && i!=454 && (strncmp(haveslist[i], compare5, (size_t)1)==0)){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
}
else if (f==3 && (strncmp(input, haveslist[i], (size_t)1)==0) && i!= 454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
}
else if (f==3 && (strncmp(input, haveslist[i], (size_t)1)==0) && i== 454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i, f);
}
else if (f==4 && (strcmp(input, haveslist[i])==0) && i != 454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
}
else if (f==4 && (strcmp(input, haveslist[i])==0) && i == 454) {
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i, f);
}
else if (f==5 && i==454 && (strncmp(haveslist[i], compare5, (size_t)1)!=0)){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s, %s\n",code[i],name[i],haveslist[i],wrapped[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i, f);
}
else if (f==5 && i==454 && (strncmp(haveslist[i], compare5, (size_t)1)==0)){
printf("\n");
if (i>=3) {
printf("#");
}
printf("%s, %s\n-----------\n%s\n",code[i],name[i],haveslist[i]);
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=0;
return(i, f);
}
else if ((i==453) && ((strcasecmp(input, code[i])!=0)||(strcmp(input, name[i])!=0))){
fclose(wrappedlist);
fclose(namelist);
fclose(codelist);
fclose(havelist);
*hPtr=1;
return(i, f);
}
}
return (0);
}
void edit (int i){
char ans[5];
char ans2[5];
char yes[] = "yes";
char no[] = "no";
char compare1[] = "on bobbin\b\b\b\b";
char compare2[] = "not on bobbin";
char compare3[] = "have\b\b\b\b\b\b";
char compare4[] = "don't have";
char wrapedit[] = "wrapped";
char haveedit[] = "have";
char editing[9];
FILE *wrappedlist = fopen("../../wrapped", "r+");
FILE *havelist = fopen("../../havelist", "r+");
fseek(wrappedlist, i*14, SEEK_SET);
fseek(havelist, i*11, SEEK_SET);
fpurge(stdin);
printf("Edit? (\"yes\"/\"no\")\n");
fgets(ans, 5, stdin);
len = strlen(ans);
ans[len - 1] = 0;
if ((strcmp(ans, yes) == 0) && (strncmp(haveslist[i], compare4, (size_t)1) == 0)) {
fpurge(stdin);
printf("Switch \"don't have\" to \"have\"? (\"yes\"/\"no\")\n");
fgets(ans2, 5, stdin);
len = strlen(ans2);
ans2[len -1] = 0;
if (strcmp(ans2, yes)==0) {
printf("Switched \"don't have\" to \"have\".");
fputs(compare3, havelist);
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans2, no)==0){
printf("Not switching \"don't have\" to \"have\".");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid entry1.");
fclose(wrappedlist);
fclose(havelist);
return;
}
else if ((strcmp(ans, yes)==0) && (strncmp(haveslist[i], compare3, (size_t)1) == 0)) {
printf("Edit \"have\" or \"wrapped\"?\n");
fpurge(stdin);
fgets(editing, 9, stdin);
len = strlen(editing);
editing[len - 1] = 0;
if (strcmp(editing, wrapedit)==0) {
if (strncmp(wrapped[i], compare1, (size_t)1)==0) {
printf("Switch \"on bobbin\" to \"not on bobbin\"? (\"yes\"/\"no\")\n");
fgets(ans2, 5, stdin);
len = strlen(ans2);
ans2[len - 1] = 0;
if (strcmp(ans2, yes)==0) {
printf("Switched \"on bobbin\" to \"not on bobbin\".");
fputs(compare2, wrappedlist);
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans2, no)==0){
printf("Not switching \"on bobbin\" to \"not on bobbin\".");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid entry2.");
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strncmp(wrapped[i], compare2, (size_t)1)==0){
printf("Switch \"not on bobbin\" to \"on bobbin\"? (\"yes\"/\"no\")\n");
fgets(ans2, 5, stdin);
len = strlen(ans2);
ans2[len - 1] = 0;
if (strcmp(ans2, yes)==0) {
printf("Switched \"not on bobbin\" to \"on bobbin\".");
fwrite(compare1, (size_t)strlen(compare1), 1, wrappedlist);
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans2, no)==0){
printf("Not switching \"not on bobbin\" to \"on bobbin\".");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid entry.");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("You don't want to edit wrapped apparently.");
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(editing, haveedit)==0){
if (strncmp(haveslist[i], compare3, 1) == 0){
printf("Switch \"have\" to \"don't have\"? (\"yes\"/\"no\")\n");
fgets(ans2, 5, stdin);
len = strlen(ans2);
ans2[len - 1] = 0;
if (strcmp(ans2, yes)==0) {
printf("Switched \"have\" to \"don't have\".");
fputs(compare2, wrappedlist);
fputs(compare4, havelist);
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans2, no)==0){
printf("Not switching \"have\" to \"don't have\".");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid entry.");
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strncmp(haveslist[i], compare4, 1)==0){
printf("Switch \"don't have\" to \"have\"? (\"yes\"/\"no\")\n");
fgets(ans2, 5, stdin);
if (strcmp(ans2, yes)==0) {
printf("Switched \"don't have\" to \"have\".");
fputs(compare3, havelist);
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans2, no)==0){
printf("Not switching \"don't have\" to \"have\".");
fclose(wrappedlist);
fclose(havelist);
return;
}
}
printf("Invalid entry.");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid Entry.");
fclose(wrappedlist);
fclose(havelist);
return;
}
else if(strcmp(ans, no)==0){
printf("Not editing.");
fclose(wrappedlist);
fclose(havelist);
return;
}
printf("Invalid entry.");
fclose(havelist);
fclose(wrappedlist);
return;
}