fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n = 16;
  5. char * input = new char [16] {'n', 'o', ' ', 'w', 'a', 'y', ' ', 't', 'h', 'e', ' ', 'f', 'u', 'c', 'y', '\0'};
  6.  
  7.  
  8. int listSize(char * s, int n){
  9. int result = 0;
  10. for(int i = 0; i < n; i++){
  11. if(*(s + i) == ' ') result++;
  12. }
  13. return result + 1;
  14. }
  15.  
  16. SList createList(char * s, int n){
  17. int _listSize = listSize(s, n);
  18. SList myList;
  19. myList.length = _listSize;
  20. myList.wordList = new Word [myList.length];
  21. int k = 0;
  22. for(int i = 0; i < n; i++){
  23. int counter = 0;
  24. char symbol = *(s + i);
  25. Word toAdd;
  26. while(symbol != ' '){
  27. symbol = *(s + i);
  28. if(i == n) break;
  29. counter++;
  30. i++;
  31. }
  32. toAdd.length = counter - 1;
  33. for(int j = 0; j < toAdd.length; j++){
  34. *(toAdd.letters + j) = *(s + i + j - (toAdd.length+1));
  35. }
  36. *(myList.wordList + k) = toAdd;
  37. k++;
  38. i--;
  39. }
  40. return myList;
  41. }
  42.  
  43. ostream &operator<<(ostream &os, SList &myList) {
  44. for (int i = 0; i < myList.length; i++) {
  45. for(int j = 0; j < myList.wordList[i].length; j++){
  46. os << myList.wordList[i].letters[j];
  47. }
  48. os << endl;
  49. }
  50. return os;
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16:1: error: ‘SList’ does not name a type
 SList createList(char * s, int n){
 ^~~~~
prog.cpp:43:34: error: ‘SList’ has not been declared
 ostream &operator<<(ostream &os, SList &myList) {
                                  ^~~~~
prog.cpp: In function ‘std::ostream& operator<<(std::ostream&, int&)’:
prog.cpp:44:32: error: request for member ‘length’ in ‘myList’, which is of non-class type ‘int’
     for (int i = 0; i < myList.length; i++) {
                                ^~~~~~
prog.cpp:45:35: error: request for member ‘wordList’ in ‘myList’, which is of non-class type ‘int’
         for(int j = 0; j < myList.wordList[i].length; j++){
                                   ^~~~~~~~
prog.cpp:46:26: error: request for member ‘wordList’ in ‘myList’, which is of non-class type ‘int’
             os << myList.wordList[i].letters[j];
                          ^~~~~~~~
stdout
Standard output is empty