Этот код работает в turbo C, но не в блоке кода.как заставить его работать на codeblock?
//WAP to calculate length of string and to get reverse of the string without using strlen() and strrev() function in C. #include<stdio.h> #include<stdlib.h> //Calculate length of the String. int length(char *p) /* *p ->When it is called so it will pass the string along with it just like strlen() we pass address. Using p we will access the string.length function whose return type is int. In parenthesis we pass string address and we make pointer(char*p).*/ { int i; for(i=0;*(p+i)!='\0';i++); //We put; here as for body doesn't exist(It has Null Statement). /*for loop working->i=0;*(p+i)means s[0]!='\0', so OK i will increment(i++),again condition will check and again increment; this loop will work till ivalue=8 i.e\0. So,i=8;*(p+8)!='\0' become false and loop stops.*/ return(i); //Means i value is 8 that we need to return as length of the string is 8.So,we write return(i); } //We make function that will reverse our string. char* reverse(char *p) //char * means here we return address. p contain address of that string we need to reverse. { int l,i; char ch; for(l=0;*(p+l)!='\0';l++); //l contains length. for(i=0;i<(l/2);i++)//We do swapping l/2 times.We start from i=0,thats why we are not writing i<=l/2. { ch=*(p+i); //*(p+i) is same as s[i].Initially, t=s[0]. *(p+i)=*(p+l-1-i);/*We do -i when i increase because of loop so p+l-1 value should decrease. l->length,we written l-1,we get last block index. If length=8. eg. 8-1=7 index last character i.e;r. So, 0 index will swap with 7 index thats why we have written this*/ *(p+l-1-i)=ch; }//Reverse done. return(p);//We are returning address of that string that has been reversed. } //Now we make main()function to use both function- length and reverse. int length(char *); char* reverse(char *); int main() { printf("Length of the String = %d",length("Computer\0")); printf("Reverse of the String =%s",reverse("Computer\0")); }
Что я уже пробовал:
У меня есть use <cstring>
используйте возврат в Главное()
Ничего не работает
Suvendu Shekhar Giri
есть сообщение об ошибке?
Sksforever
| / = = = Файл сборки: "нет цели" в "нет проекта" (компилятор: неизвестен) ===|
C:\Users\Dell_5\Desktop\C_Tutorial\WAPTOC~1. C| / в функции ' int main()':|
C:\Users\Dell_5\Desktop\C_Tutorial\WAPTOC~1. C / 31 / warning: устаревшее преобразование из Строковой константы в 'char*' [- Wwrite-strings]|
C:\Users\Dell_5\Desktop\C_Tutorial\WAPTOC~1. C / 32 / warning: устаревшее преобразование из Строковой константы в 'char*' [- Wwrite-strings]|
/ / = = = Сборка завершена: 0 ошибок, 2 предупреждения (0 минут, 1 секунда) ===|
Sksforever
Длина строки = 8 идет, но обратная строка не идет