| | |
Null Terminated Arrays
![]() |
•
•
Join Date: Sep 2003
Posts: 22
Reputation:
Solved Threads: 0
0
#2 Sep 8th, 2003
Do you know the position of the char?
If so:
char_array_name[position] = new_character;
char_array_name is the name of the array.
position is an integer value specifying the offset from the address of the start of the array.
new_character is the character you want it to replace it with, like 'A'.
If you don't know it:
temp is a pointer to the array
array is the name of the array
character is the numberical value of the character you want to find
new_character is the character you want it to change to
It'll search the array, and replace the first instance of the character you want changed to the character you want it to be.
If you want to search the whole array:
If you want to output it, just go:
printf("%s",array);
where array is the name of the array.
Alternatively, you can go with 'cout', but I like printf() better, I guess since C is the first language I learned.
If so:
char_array_name[position] = new_character;
char_array_name is the name of the array.
position is an integer value specifying the offset from the address of the start of the array.
new_character is the character you want it to replace it with, like 'A'.
If you don't know it:
C Syntax (Toggle Plain Text)
register char *temp = array; while (*temp++ != character && *temp != 0); *temp = new_character;
temp is a pointer to the array
array is the name of the array
character is the numberical value of the character you want to find
new_character is the character you want it to change to
It'll search the array, and replace the first instance of the character you want changed to the character you want it to be.
If you want to search the whole array:
C Syntax (Toggle Plain Text)
register char *temp = array; while (*temp++!=0) if (*temp == character) *temp = new_character
If you want to output it, just go:
printf("%s",array);
where array is the name of the array.
Alternatively, you can go with 'cout', but I like printf() better, I guess since C is the first language I learned.
Last edited by Mike29936; Sep 8th, 2003 at 12:19 am.
![]() |
Similar Threads
- How to read null-terminated strings from file? (C)
- Three questions (C++)
- Differences Between Java and C/C++ (C++)
- quick question: how to 'null' blocks of an unsigned char array (C++)
- functions using strings and arrays (C++)
- Hey Just started new topic with arrays, and having some trouble please help (C++)
- adding numbers of binary output (C)
- Sorting arrays of pointers with function? (C)
Other Threads in the C Forum
- Previous Thread: Launching program from resources
- Next Thread: ATL Web Service
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi





