Computer Science & C Programming


Text analysis

  1. Create a file text.c that displays "Text 's Analysis" on screen and execute it.
  2. Define the text txt = "hello" and display it on screen.
  3. Compute and display it's length (in the main program).
    We recall that a text end with \0
  4. Define txt2 = "babel" and compute the "dot product" between txt and txt2 (in the main program) ; print the result.
    Also display the product between txt and itself.
  5. Transform length(txt) and dot(txt,txt2) into two sub-programs and adapt the main to use them.
  6. Define a subprogram norm(txt) that computes the square root of dot(txt,txt) ; you can use the function sqrt from math.h.
    Nb. The result must be a real number.
  7. Define a subprogram correlation(txt,txt2) that returns the dot produt divided by the norm of each text.
    Also display the correlations for (txt,txt), (txt,txt2) and (txt,"wasty").
  8. By defining the following variable, compute then display the position having the maximum correlation with guess (i.e. i such as correlation(guess,words[i]) is maximum).
char* words = {txt2,txt,txt3};
char guess = "...";

Nb. txt3 = "wasty"

  1. Test your program with "hello", "hallo", etc.
    A sample result can be:
'hallo' ? ... Maybe it's 'hello' ?
=>DEPOSIT HERE<=