Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Need help with a C programming Homework

+1 vote
asked Apr 29, 2020 by Iftiaq (620 points)
Simply encrypt a string, add 1 to the ASCII code of each character, and then print out the encrypted string.

2 Answers

+1 vote
answered Apr 29, 2020 by arifim (460 points)
selected Apr 30, 2020 by Iftiaq
 
Best answer
#include <string.h>

#include <stdio.h>

int main() {

      char str[] = "some string";

      for (int i = 0; i < strlen(str); i++) {

             str[i] = (int)str[i] + 1;

       }

      printf("%s", str);

      return 0;

}
+1 vote
answered Apr 30, 2020 by mark (360 points)

I tried this but and it failed but here's my code in c++

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
using namespace std;

char chpeir[52]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','!','@','#','$','%','^','&','*','(',')','-','_','=','+','[',']','{','}'};
char text[500];
char chpier_text[500];
int main()
{
    cin>>text;
        for(int letter = 0;letter<500;letter++)
    {
           for(int letter_find=0;letter_find<52;letter_find++)
        {
                if(chpeir[letter_find]==text[letter])
            {
                chpier_text[letter]=chpeir[((letter_find+26)%52)];
                break;
            }
           
        }
       
    }
    cout<<chpier_text;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...