hi
The question to which am using the for loop is as follows:

Write a C interactive program that will encode a word or sentence entered by a user. The
encryption will be done as follows:
For any word or sentence (note: blank spaces, special characters are ignored here, i.e
they are not changed) entered, each character is encrypted by changing it to the next
adjacent letter of the alphabet.
Thus if the letter ‘a’ is entered it is changed to ‘b’,
if the word ‘zorro’ is entered it will be changed to ‘apssp’,
if the sentence ‘I am a good programmer’ is entered it will be encrypted to ‘J bn b hppe
qsphsbnnfs’.

If am usig the for loop to slove this question,how can i add more than one condition to the for loop to run this program properly.

My piece of code is as follows:

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
  char sentence[100];
  int type;
  printf("Enter the word or sentence to be encrypted: \n");
  scanf("%[^\n]",&sentence);
  for (type=0; sentence[type]!= '\0'; ++type)
  {
     
                 putchar(sentence[type]+1);
      
  }
 
  system("PAUSE");	
  return 0;
 }

[here it is not catering for spaces and the last alphabeth z it is not converted to a][to achieve this we have to include different conditions]

The conditions that i want to add in the loop is as follows :

(sentence[type] == 'Z' ) putchar ('A');
(sentence[type] == 'z' ) putchar ('a');
(sentence[type] == ' ' ) putchar (' ');

the problem is that i don't wana use the if else if loop in that.so how can i integrate these conditions in the for loop

fnxs for ur kind future help :)

You should be able to or your conditions together.

The conditions that i want to add in the loop is as follows :

(sentence[type] == 'Z' ) putchar ('A');
(sentence[type] == 'z' ) putchar ('a');
(sentence[type] == ' ' ) putchar (' ');

the problem is that i don't wana use the if else if loop in that.so how can i integrate these conditions in the for loop

Use regular IF statements within the loop.

1. Use if statements for replacing 'z' and 'Z' (recommended).
2. Check for characters falling under required series [Eg. (65 - 90) and (97 - 122) as in your case]. Everything else should be discarded.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.