- Joined
- Nov 19, 2022
- Messages
- 2
- Reaction score
- 0
Hi!
Basically I tried to create a program that is shifting the components of an array.
Now I get a warning for the i < textlaenge part.
I think the textlaenge (textlength) part became a pointer somehow but I thought I'd have defined it as an Integer.
Do you have any idea? It would help me a lot!
Thanks in advance!
#include <stdio.h>
int textlaenge(char text[]) {
int laenge = 0;
while (text[laenge] != '\0') //mit '\0' werden C-Strings abgeschlossen
++laenge;
return laenge;
}
void shiftString(char text[], int shift) {
for(int j = 0; j < shift; j++){
for(int i = 0; i < textlaenge; i++){
if(i < textlaenge - 1)
text = text[i+1];
else
text = text[0];
}
}
}
int main(void) {
char str[25] = "Das ist der Originaltext"; // Originaltext
printf("Original: %s\n", str);
shiftString(str, 5);
printf("Verschoben um %d stellen: %s\n", 5, str);
shiftString(str, 19);
printf("Nochmal um um %d stellen verschoben: %s\n", 19, str);
}
Basically I tried to create a program that is shifting the components of an array.
Now I get a warning for the i < textlaenge part.
I think the textlaenge (textlength) part became a pointer somehow but I thought I'd have defined it as an Integer.
Do you have any idea? It would help me a lot!
Thanks in advance!
#include <stdio.h>
int textlaenge(char text[]) {
int laenge = 0;
while (text[laenge] != '\0') //mit '\0' werden C-Strings abgeschlossen
++laenge;
return laenge;
}
void shiftString(char text[], int shift) {
for(int j = 0; j < shift; j++){
for(int i = 0; i < textlaenge; i++){
if(i < textlaenge - 1)
text = text[i+1];
else
text = text[0];
}
}
}
int main(void) {
char str[25] = "Das ist der Originaltext"; // Originaltext
printf("Original: %s\n", str);
shiftString(str, 5);
printf("Verschoben um %d stellen: %s\n", 5, str);
shiftString(str, 19);
printf("Nochmal um um %d stellen verschoben: %s\n", 19, str);
}