Dagbfatih
Dagbfatih

Reputation: 1

C language, Changing the data I write to the console

I am writing a library program and I want to organize data on books in a .txt file. I want to be able to change the title of the book as I want instead of rewriting the title after printing it on the screen.

    char bookName[30] = "A Clockwork Orange";
    printf("Edit Book Name --> %s", bookName);
    gets(bookName);

If I use the program I wrote above, it will be like this:
Edit book name -> _
the cursor will stop here (_) and I will have to rewrite the title.

I want to do this:
Edit book name -> A Clockwork Orange_
I want to change the bookName variable I printed on the screen, not rewrite it.

I would be glad if you help

Upvotes: 0

Views: 270

Answers (2)

Dagbfatih
Dagbfatih

Reputation: 1

Thank you, but what I wanted is still not fully understood :) Maybe because my English is a bit poor. Now the thing is as follows; I have already saved the books saved in the library to a file (.txt). I get the name of a book I want from the file, edit it and save it again. Take the 3rd book for example: Inside the file:

  1. To Kill A Mockingbird
  2. Brave New World
  3. A Clockwork Ornage
  4. The Secret History

We read the 3rd book from the file and assign it to the variable named bookName:

fgets(bookName, 30, file); 

Now I want to edit this book because as you can see above, I misspelled the title of the book (A Clockwork Ornage).
I want the program to:
When I tell my program that I want to edit it, the program will print

Edit Book Name -> A Clockwork Ornage

And I will click on the 15th character ('a') with the mouse and I will delete 2 characters (with backspace) and type "an" and now the console will write:

Edit Book Name -> A Clockwork Orange 

   

And by pressing 'enter' I will change the value of the bookName variable to its new value, its new value will be: "A Clockwork Orange". Here I could not do the part up to here. This is where I stumble, how can I change something I have printed to the console with printf().

Upvotes: 0

Aladin Cherki
Aladin Cherki

Reputation: 23

you can use the following code :

char bookName[30] = "A Clockwork Orange";
    printf("Edit Book Name --> %s \n", bookName);
    printf("editing book name ...");
    scanf("%s",bookName);
    printf("your new Book Name --> %s", bookName);

    return 0;

Upvotes: 2

Related Questions