| | |
Reading and editing characters in a string
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 28
Reputation:
Solved Threads: 0
I need to edit every character of a string for an assignment; apply a simple Caesar cipher on it. What is the C equivalent of "charAt()"? I remember my prof saying that all strings are terminated with a certain character in C and that you could run a while loop till that character, but I'm not sure how to do it.
0
#2 Nov 10th, 2009
C string is an array of characters. You may set or get a character at specific index.
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="ABC"; str[0]='a'; // replace 'A' with 'a'
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="Sample Text"; int i=0; while(str[i]!='\0') { /* put your code */ i++; }
Last edited by adatapost; Nov 10th, 2009 at 7:20 am.
•
•
Join Date: Oct 2009
Posts: 28
Reputation:
Solved Threads: 0
0
#3 Nov 10th, 2009
•
•
•
•
C string is an array of characters. You may set or get a character at specific index.
C Syntax (Toggle Plain Text)
char str[20]="ABC"; str[0]='a'; // replace 'A' with 'a'
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="Sample Text"; int i=0; while(str[i]!='\0') { /* put your code */ i++; }
Thanks. I ended up doing something similar.
![]() |
Similar Threads
- Reading Characters from a String in C? (C)
- Capitalizing all characters of a string (C)
- Adding in escape characters into a string (C#)
- Count characters of a string. (C++)
- Counting all Non-blank Characters in a String (Java)
- Counting specific characters in a string (C)
- Removing characters from a string (C)
Other Threads in the C Forum
- Previous Thread: Link for OS Concepts code for C
- Next Thread: Reverse of number
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






