This isn't cheating. This is C in the year of 2017!
getch() was in the standard of 89/90, was deprecated in the standard of 99 and is no longer part of the standard from 2011.
Your instructor should learn that the programing language C is under a development process, like all other languages.
There is no advantage if student learn old and outdated practices. Rather, we have in the future programs with buffer overflow and undefined behavor and when we look why this happens, the programer from tomorrow will say: 'we have learn it this way'.
I mean, all instructors should look at the last standard and all schoolbooks should be updated to reflect the new standard.
The instructor can show you the old functions, but only that students know it and this functions can be in old code.
New code should allways be written to be accordant to the new standard.
Also, please consider what we have told you:
avoid global variables, hold the scope of variables as small as possible
avoid magic numbers, instead use #define
don't use fflush() on an input stream
don't use deprecated or outdated functions, instead use the new and safer functions
I think other members of this forum will complete this list, because i am a self learning hobbyist and not a full trained programer.
Other have classes, we are class
This is a good and polite manner to say things and I appreciate it. Just remember because I told you lots of times: this is not my field of knowledge, this is not what I must do to earn a salary and I am starting learning. If I asked you is because I wanted to follow the course that I took just to gain a new skill not because I will be a developer, is ridiculous! if I wanted to be a developer I should have studied computer sciences. As you know and if you don't know I tell you, at least in my country almost every engineering degree has a subject about programming. I almost forgot everything about this subject + in an engineering degree you don't really understand anything but loops and barely syntaxis. I just want to understand some basics about a language, nothing more like this, is not my field. If I have time, surely I will keep on studying further from this course. But is just a course, you know? I will have a job interview this friday, I am unemployed and this fact is 1000000000000000 times more important than passing a course, even if I fail this course and don't get a "diploma" but just have even a single job interview I will be the happiest guy around the world. Anyway, tomorrow we will have 20 minutes to ask about the project, the only exercise we must submit to be evaluated. Out of 6 functions I failed modifying, I am trying to solve it and I know I have a memory leak but that's ok... If I learn something it worths the money. Understanding all the concepts will take more time, I do not have the practice that most of you surely have. I am not happy with this course because apparently you must have some knowledge of programming to pass it and finally was out of my possibilities since went faster than what I can understand but at least I understood something in case I need it in a future job, not related with programming.
Ooops, yes, i mean gets, sorry.
@JorgeChemE
Your search will never end.
Here is a skeleton that should work.
You don't need to allocate memory for a new struct, because you want to edit one.Code:#define NAME_MAX 100 void modificar_mascota() { char nombre_mascota[NAME_MAX]; tmascota *temp; if (primero == NULL) return; // check if we have a valid pointer printf("\nIntroduzca el nombre de la mascota a modificar: "); fflush(stdout); fgets(nombre_mascota, NAME_MAX, stdin); temp = primero; while (temp) { // same as 'temp != NULL' if (strcmp(temp->nombre_mascota, nombre_mascota) == 0) break; temp=temp->siguiente; } if (temp) { // edit the pet where 'temp' points to } else { printf("Sorry, no pet found\n"); } }
The while-loop will break if the pet was found, otherwise it runs until there is no more pets in the list and temp become NULL.
But this is a quick and dirty solution, because if the name of the pet is 'Charly' and you enter 'charly', the pet will not be found (case sensitive).
PS: this code is untested, i have it written out of my head.
Last edited by WoodSTokk; 06-01-2017 at 05:13 AM.
Other have classes, we are class