Recent

Author Topic: show number of space in a string chaine  (Read 1705 times)

whitehat

  • Jr. Member
  • **
  • Posts: 93
show number of space in a string chaine
« on: January 14, 2017, 04:19:55 pm »
there's some problem when i wanna write the number of space in a string chaine tthe program show me les espace 1ere = 0
les espace 2ere = 0
Code: Pascal  [Select][+][-]
  1. program ex;
  2. uses wincrt;
  3.  
  4. var
  5.  
  6. ch:string;
  7. procedure saisie (var ch :string);
  8. begin
  9. repeat
  10. writeln('donner le mot');
  11. readln(ch);
  12.  
  13. until ch<>'';
  14. end;
  15. procedure sup (var ch:string);
  16.  
  17. begin
  18. while pos (' ',ch) <> 0 do
  19. delete (ch,pos(' ',ch),1);
  20. end;
  21. function nb (ch:string):integer;
  22. var
  23. i,n:integer;
  24. begin
  25. n:=0;
  26. for i:=1 to length(ch) do
  27. if ch[i]='' then
  28. n:=n+1;
  29. nb := n;
  30. end;
  31. begin
  32. saisie(ch);
  33. writeln('les espace 1ere ',nb(ch));
  34. sup(ch);
  35. writeln('les espace 2ere ',nb(ch));
  36. write(ch);
  37. end.
  38.  

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: show number of space in a string chaine
« Reply #1 on: January 14, 2017, 04:46:49 pm »
function nb should be (you're counting spaces, not nulls, right?)
Code: Pascal  [Select][+][-]
  1. function nb (ch:string):integer;
  2. var
  3.   i,n:integer;
  4. begin
  5.   n:=0;
  6.   for i:=1 to length(ch) do
  7.     if (ch[i] = ' ') then
  8.       n:=n+1;
  9.   nb:=n;
  10. end;    

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: show number of space in a string chaine
« Reply #2 on: January 14, 2017, 04:54:27 pm »
yes true

 

TinyPortal © 2005-2018