fork download
  1. //Naam: Martijn Valk
  2. //Nummer: 18031722
  3. //Opdracht: 1
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. int checkHoofdletter(char c) {
  9. if(c >= 'A' && c <= 'Z') {
  10. return 1;
  11. } else {
  12. return 0;
  13. }
  14. }
  15.  
  16. int main()
  17. {
  18. char input[50], achternaam[50], tussenvoegsels[20], voornaam[50];
  19. int i,o,p,x;
  20.  
  21. printf("Geef je naam: ");
  22. fgets(input,sizeof(input),stdin);
  23. input[strlen(input)-1] = '\0';
  24.  
  25. if(checkHoofdletter(input[0]) == 0) {
  26. printf("De voornaam moet met een hoofdletter beginnen!");
  27. exit(0);
  28. }
  29.  
  30. //achternaam
  31. for(x = strlen(input)-1; x > 0 && input[x] != ' '; x--) {}
  32.  
  33. for(i = x+1; i <= strlen(input)-1; i++) {
  34. achternaam[i] = input[i];
  35. printf("%c , %c\n",input[i], achternaam[i]);
  36. }
  37. achternaam[i+1] = '\0';
  38.  
  39. //voornaam
  40. for(o = 0; input[o] != ' '; o++) {
  41. voornaam[o] = input[o];
  42. }
  43.  
  44. printf("%d, %d ",o,x);
  45.  
  46. if(o == x) {
  47. printf("%s, %c.",achternaam,voornaam[0]);
  48. }
  49.  
  50. //check voor tussenvoegsels
  51. /*for(chk = x; chk > 0; chk--) {
  52.   if(input[chk] == ' ') {
  53.   tc++;
  54.   }
  55.   }*/
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 5696KB
stdin
Standard input is empty
stdout
Geef je naam: De voornaam moet met een hoofdletter beginnen!