can any one help me in my code ,he didn't work in my bc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

can any one help me in my code ,he didn't work in my bc

//have be the input is (abababaaaaaab) //and the resolt is "Right" #include <stdio.h> #include <stdlib.h> #include <string.h> int longer(char phr[50],int i){ if(phr[i]=='\0'){ return 0; }else{ return longer(phr,i+1)+1;}} int occurrence(char phe[],char a){ int k=0; for(int i=0;i<=longer(phe,0);i++){ if(phe[i]==a){ k=k+1; }}return k;} int longage2(char phe[ ]){ if (strlen(phe)==1||strlen(phe)%2!=0||phe[strlen(phe)]=='a'){ return 0; } for(int i=0;i<strlen(phe);i++){ if(i%2==0){ if(phe[i]!='a'){ return 0; }}else{ if(phe[i]!='b'){ return 0;}} }return 1;} int longage3(char phe[]){ int a=occurrence(phe,'a'); if(occurrence(phe,'a')%2!=0){ return 0;} else{ for(int i=0;i<occurrence(phe,'a');i++){ if(phe[i]!='a'){ return 0; }} if(occurrence(phe,'b')==0){ return 0; }} return 1;} int longage4(char phe[]){ int a,k,j;char ph1[30]; if(phe[0]!='a'){ //||occurrence(phe,'a')<3 || occurrence(phe,'b')<2 return 0; }else{ for( int i=0;i<=longer(phe,0)-1;i++){ ph1[i]=phe[i]; if(longage2(ph1)==1){ a=i; }} if(a<1){ return 0; } char ph2[a+2]; for(int j=0;j<=a;j++){ ph2[j]=ph1[j]; } ph2[a+1]='\0'; //------------------------------------ char ph3[longer(phe,0)-(a+2)+1]; for (int o=a+1;o<=strlen(phe);o++){ ph3[k]=phe[o]; //printf("%d\n",longage3(ph3)); k=k+1; } ph3[strlen(ph3)+1]=='\0'; if(longage2(ph2)==1 &&longage3(ph3)==1){ return 1; }else{ return 0; }}} int main() {char phe[50]; printf("donnez un mot\n"); scanf("%s",phe); if (longage4(phe)==1){ printf("Right"); }else{ printf("Wrong");} return 0; }

23rd Oct 2020, 10:16 PM
mar ia
mar ia - avatar
17 Answers
+ 3
mar ia look at this : Is this not correct one which are you looking? //changes mentioned in comments. https://code.sololearn.com/cnrr87I734Pf/?ref=app
24th Oct 2020, 3:25 PM
Jayakrishna 🇮🇳
+ 2
mar ia You have uninitialized variables access causing to code crash.. Assign values before using it. In 1st function return i; instead return 0; You are using == operator instead of '=' for assigning '\0'.. In loop conditions, use < only instead of <= Instead writing code in description, copy to playground and share the link here.. That's helps to identify issue easily.. Pls Tag the language c instead c#. Reply after modifications if still not work..
23rd Oct 2020, 10:44 PM
Jayakrishna 🇮🇳
+ 2
Thank you to everyone who contributed to finding a solution with me. I just want to tell you that I found the solution with your help. Thank you from the bottom of my heart.💛💛
24th Oct 2020, 8:39 PM
mar ia
mar ia - avatar
+ 1
mar ia please learn to do this: Copy your code and go on your profile, then on "code bits", then click the "+" to create a new code. Put there your code and save it, with any name you want. Don't forget to make it public! Then come back here in the comments and click the "+" to insert a code. You'll find your code in your code bits. After you added your code to the comment we can all help you in a better and easier way! And the next times add the code directly in the question, instead of doing it in the comments. Many thanks 🤗
24th Oct 2020, 12:17 PM
Davide
Davide - avatar
24th Oct 2020, 12:52 PM
mar ia
mar ia - avatar
+ 1
I did it. Thanks for the help😊
24th Oct 2020, 12:54 PM
mar ia
mar ia - avatar
+ 1
Ab*n -->ab*2=aabb ab^(2n)--> exp:n=1->ab^2=abab
24th Oct 2020, 2:41 PM
mar ia
mar ia - avatar
+ 1
The program works good ,but ther is bug When i input (ababababaaaaaab) The reasoult should be :abababab aaaaaab Right But he didn't work And in my pc he didnt work in the boocl i but comment in thes boocl https://code.sololearn.com/c7koXSD6pq0I/?ref=app
24th Oct 2020, 6:03 PM
mar ia
mar ia - avatar
+ 1
I use code blocks 17.12 in my pc
24th Oct 2020, 6:04 PM
mar ia
mar ia - avatar
0
Program work is longage 2=Test the word if it belongs to ab^(2n).......n>1 exp:ab or abab or ababab ........ longage 3=Test the word if it belongs to a^(2n) b^(m)......m&n>1 exp:aab or aaaab ........ longage 4=looking for longage 2 and longage3 in the word With this rool (longage4=longage2.longage3).......exp(longage4=abaab-->longage2=ab+longage3=aab)
24th Oct 2020, 8:44 AM
mar ia
mar ia - avatar
0
Jayakrishna🇮🇳 in 1st function i return 0 not i It's wrong The 1st fonctin works well alone I have a problem whith the fanction nember 5
24th Oct 2020, 8:51 AM
mar ia
mar ia - avatar
0
mar ia in line 71 you need "=" instead of "==" And in line 59 you don't need the "int" inside the for. Write for( j=0... If you make this changes to the code that you posted, then everyone will see the new corrected version. The code is still not working, but we are doing progress 😅
24th Oct 2020, 1:07 PM
Davide
Davide - avatar
0
There is no problem, I am still looking into the error, and I will try again until I find a solution💪💪
24th Oct 2020, 1:30 PM
mar ia
mar ia - avatar
0
Program work is longage 2=Test the word if it belongs to ab^(2n).......n>1 exp:ab or abab or ababab ........ longage 3=Test the word if it belongs to a^(2n) b^(m)......m&n>1 exp:aab or aaaab ........ longage 4=looking for longage 2 and longage3 in the word With this rool (longage4=longage2.longage3).......exp(longage4=abaab-->longage2=ab+longage3=aab) For longage2: ab or abab or ababab means ab*n I don't know what ab^(2n) means. For longage3 is the same: aab or aaaab means a*n and then b For longage4 I got that calls longage 2 and 3. Anyway the only way you can make this program work is to add comments everywhere. Write a comment for every line of code, explaining what is exactly doing. You don't do it to make other people understand your code as much as you do it to make yourself understand what the code is actually doing. If you do this (addin comments everywhere) you will probably find things to fix. When you are done you either have a working program, or a non-working program that is easy to check.
24th Oct 2020, 2:08 PM
Davide
Davide - avatar
0
how to input something
25th Oct 2020, 2:42 PM
Honiish Hassan
Honiish Hassan - avatar
0
how to input something the input is abababaaaaaab
25th Oct 2020, 2:44 PM
mar ia
mar ia - avatar
0
mar ia I think he speaks about input something in general, not in your code. He is new and he thinks he's asking a question rather than commenting another question. So cute. Anyway I am happy for you that you finally solved the problem! 🤗
25th Oct 2020, 2:48 PM
Davide
Davide - avatar