vendredi 27 avril 2018

Writing to file and using if statments with loops

I am creating a simple system for people to enter there basic details, have them printed on the screen and once confirmed writen to a text file, is the info is wrong the user enters edit ot be looped back to the beginning of the report and if another input is ented it asks the question again. Im a struggling to get the print to file to work and the two end loops.

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

int get_line(const char *prompt, char *dest, size_t size) {
  printf("%s", prompt);
  fflush(stdout);
  if (fgets(dest, size, stdin) == NULL) {
    dest[0] = '\0';
    return 0;
  }
  dest[strcspn(dest, "\n")] = '\0';  // Lop off potential trailing '\n'
  return 1;
}

int main(void) 
{
    char first_name[20], surname[20], street_no[10], street_name[40], postcode[10], contact_no[20], save_edit_qu[10];
    int dd, mm, yy;
    get_line(" Enter first name:\n", first_name, sizeof first_name);
    get_line(" Enter surname:\n", surname, sizeof surname);
    get_line(" Contact Number\n", contact_no, sizeof contact_no);
    get_line(" Street Number\n", street_no, sizeof street_no);
    get_line(" Street Name\n", street_name, sizeof street_name);
    get_line(" Postcode\n", postcode, sizeof postcode);

    printf(" First Name : %s\n", first_name);
    printf(" Surname    : %s\n", surname);
    printf(" Contact No.: %s\n", contact_no);
    printf(" Street No. : %s\n", street_no);
    printf(" Stret Name : %s\n", street_name);
    printf(" Postcode   : %s\n", postcode);


    get_line(" If the informations above is correct please enter SAVE/if you wish to change any informations please enter edit", save_edit_qu, sizeof save_edit_qu);
    if (save_edit_qu[0] == 'SAVE' || save_edit_qu[0] == 'save') {
    //write info to file
    }
    if (save_edit_qu[0] == 'EDIT' || save_edit_qu[0] == 'edit') {
    //loop back to beginning of report
    }
    else if ()//loop to beginning of SAVE/EDIT QU

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire