| | |
Algorithm for substitution encryption
![]() |
•
•
Join Date: Nov 2008
Posts: 78
Reputation:
Solved Threads: 1
Can someone explain to me what I'm doing wrong
OUTPUT:
fghijklmnopqrstuvwxyzabcde
Prints the whole enc array in order.
How do you print an individual character, not the entire array in C?
C Syntax (Toggle Plain Text)
#include <stdio.h> main(){ char ch = 'd'; char alp[26] = {'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'}; char enc[26] = {'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e'}; for(int i = 0; i <= 26; i++){ if(ch = alp[i]){ printf("%c", enc[i]); } } return 0; }
fghijklmnopqrstuvwxyzabcde
Prints the whole enc array in order.
How do you print an individual character, not the entire array in C?
>for(int i = 0; i <= 26; i++){
I'd start with this. When you declare an array of 26, it means that the last valid index is 25. This loop runs off the end of the array.
>if(ch = alp[i]){
This is a common mistake too. The operator for equality is ==. The operator for assignment is =.
>How do you print an individual character, not the entire array in C?
Um, don't loop?
I'd start with this. When you declare an array of 26, it means that the last valid index is 25. This loop runs off the end of the array.
>if(ch = alp[i]){
This is a common mistake too. The operator for equality is ==. The operator for assignment is =.
>How do you print an individual character, not the entire array in C?
Um, don't loop?
I'm here to prove you wrong.
![]() |
Similar Threads
- Plzz help me out!!!! (C++)
Other Threads in the C Forum
- Previous Thread: strings
- Next Thread: How to measure C execution time
| Thread Tools | Search this Thread |
#include * ansi api array arrays binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socket socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






