TP6 : Entrées/sorties haut niveau

This document is written as a support material for the group L3-Inter. It should be used together with the TP6 subject available on the page Moodle of the course Advanced C Programming.

  1. Read the description of the exercice carefully and explain in a few words what are the "subtilités de scanf"
  2. Take few minutes to read the man page of scanf ($: man scanf) and explain the differences among scanf, fscanf and sscanf
  1. Compile and test the program given in the exercise with integer values and non integer values. Observe and explain what are the problems. Pay attention to the line (void)scanf("%d\n",&i);
  2. Take few minutes and propose a solution by using fgets and sscanf. The idea is that we want to read all the input data in an array and then process the data.
  3. Solution : tp6_ex1
  4. Improve this solution to allow the user to enter two integers separated by a space and read the two values.
  5. To explore : we can also use gets() to read an input stream to a char pointer; however, you will get an warning message by gcc saying that the usage of gets() is not safe. Why ?
  1. Identify the format of the two expressions. The following information can be found in the man page of scanf
  2. In the previous exercise, we have seen the usage of sscanf : n = sscanf(chaine,"%d",&i). Propose a solution for this exercise by using the same technique.