Why not getting string output | SoloLearn: Learn to code for FREE!

0

Why not getting string output

Not printing final string may be not asign string properly https://code.sololearn.com/cWqBZcmSfqZe/?ref=app

8/9/2020 5:09:19 PM

On!oN

16 Answers

New Answer

+2

The error is because of You don't include ctype.h header file in which isdigit() predefined function Declared Use Header file #include<ctype.h> After it There is no Error😉😉

+2

Can you give an example of what you are expecting as output from a given input? I didn't get the point of writing your strupr and strlwr functions. Correct me , your intention is to just check if the current character is an uppercase or lowercase character, isn't it? If yes then why not simply check if(isupper(strin[i]) or for lowercase islower(strin[i]). include <ctype.h> More over your range checking in your upper and lower functions is wrong, can't say if that is done on purpose or not upper case alpha range 65 - 91 and lowercase range 97-122

+2

Ok, and what's the logic for mod 28(%28) say if your character is X (89 ascii) add pad of 3, value goes out of range becomes 92, you would be writing A instead of X, but your formula will give (92 % 28) + 65 = 73 = I (uppercase I) is that what you want ? And what are you doing here? Looping for nothing? if(strin[i]==special_char[i]) { //for special char int n; n=strlen(special_char); for(int j=0; j<n;j++) { strout [i]=strin[i]; } }

+1

processing input before reading user input? else if(1)? in special char checking and padding. if the character is not digit, then second else-if will always execute, and the code will never go in last else-if and array will never get filled with padding chars. after you come out of loop and terminating '\0' to make strout a string.

+1

And what do you do if padding takes the character out of range of digits, upper and lowercase alphabets?

+1

Of course you will get core dump, the parameter to isupper or islower function is a character not a string. You haven't read my comment properly.

+1

Say you have a string [email protected]?34 and pad = 3 str[i] + pad gives you de now 9 + 3 is 12 and you do 12%10 = 2 you put 2 and now you have de2 but where you will add remaining 1? add to the next character?

+1

All you need is this int main(){ char strin[21], strout[21]; printf ("\n enter pass to encryption:\n"); printf("\ncharacters allowed are: @,#,₹,_,&,?,!,$,. \n"); //value of pad upto 10 int pad = 3; //rand()%10; int i;//,t; printf("\npadding = %d\n",pad); //getting input fgets(strin,20,stdin); //printing plain pass printf("\n\nplain password = %s\n",strin); //computing size // do not unnecessarily loop till sizeof the array //int n=sizeof(strin)/sizeof(strin[0]); int n = strlen(strin); for(i=0;i<n;i++) { //checking for digit if(isdigit(strin[i])) { strout[i] = (strin[i]-48+pad)%10 + 48; } else if(isupper (strin[i])) //659197122 { strout[i] = (strin[i]-65 + pad)%26+65; } //for lower case else if(islower(strin[i])) { strout[i] = (strin[i]-97 + pad)%26+97; } else { // copy special char as it is strout[i] = strin[i]; } } strout [i++]='\0';//terminating printing encrypted pass

0

~ swim ~ Carlo Sonic John Wells HonFu ★ Don’t Know ★ Ahmed Mahmoud Ace MCGAmedCoder gamerArtist AJ #L1G3 ~ swim ~ i tried with another approach can u see once again but same problem occurs https://code.sololearn.com/cl5zSolGtCXr/?ref=app

0

~ swim ~ input=abcAD123₹# If pad=3 Output should be = defDG456₹# Just try to encrypt password by adding padding to its value.

0

Carlo thanks for lib function tips

0

~ swim ~ Edited https://code.sololearn.com/c999GCYvVwje/?ref=app Now core dumped warning

0

~ swim ~ i had do digit if gets >9 then digit%10 and it will be under 0 to 9 And for lower char i put char%28+65 it may be also within the char value loop and also done for upper char

0

~ swim ~ sorry and thanks. Now theres no error but calculation error its not working as i thought . edited:but it was working for digit and special char but now both are not working.

0

U haven't to add remaining 1 It will work like 0 1 2 3 4 5 6 7 8 9 If enter 9 and pad =3 Then it will 12 , 12%10=2 So now start counting from 0 From pad is 3 therefore 2 is output sme method is used for char also

0

And i stuck on the error so i did not focus on useless loop edited: the special char loop is not useless is for checking if any specific char occurs then check from loop and place at string as output.