This is a follow up question to a previous question I asked about calculating a straight hand..not exactly the same...This is the method to read in cards- it works- but is ... |
i try to put 8 byte character into the equation causing a lot of error,what i'm supposed to do to make sure the equation can take the static value and produce ... |
When we define a character array as 'char name[10]', this indicate that the array 'name' can hold a string of length ten character. But in the program shown below the array ... |
I've got an LCD, connected to an Atmega32, working with single characters using this function:
void send_char(uint8_t c){
PORTD = c; // set the output pins to the ascii ...
|
typedef struct employee
{
int age;
char name[30];
} emp_t;
emp_t * e;
int main( )
{
printf("\nName : ");
scanf("%s", &e->name);
...
|
void main()
{
char name[20];
printf("\n enter Your Name: ");
gets(name);
switch(name)
{
default : printf( "Invalid" );
}
getch();
}
So may question ... |
|
|
Hi, What is the best syntax to use a char to index into an array. /////////////////////////////////// For example int data[256]; data['a'] = 1; data['b'] = 1; /////////////////////////////////// gcc is complaining about this syntax, so i am using static cast on the character literal. Is there a better way to do this? Thanks, Ivan |
|
|
Wondering Wanderer wrote:[color=blue] > If I declare a character array ( say, char arr[10] ), how do I see the > address of the first element of the array ? simply using cout << arr > or cout << &arr displays the entire string in the array, not the > address.[/color] cout << static_cast(arr); V -- Please remove capital 'A's when ... |
Hello, I was wondering if anyone knew how to display each letter of a character array on a separate line without doing a printf for each one. I made an example in the code below. If I wanted to display 'H' on the 1st line, 'e' on the next, etc., how would I do that? It just displays Hello 5 times ... |
|
It is because you are trying to put characters which aren't in the ASCII-table into a char. Encoding is a headache, look into things like UTF-8, unicode etc. if you want to know more about it. The problem is that is a multibyte char, and can't be represented by a single byte. This is actually a very interesting blog post ... |
#include char *myStrCpy(char*, char*); int main() { char string[] = "Mary had a lamb."; char copy[10] = "012345678"; *myStrCpy( copy, string ); printf("%s\n", copy); } char *myStrCpy( char dest[], char source[] ) { int i = 0; while ( source[i] != '\0' ) { dest[i] = source[i]; i++; } dest[i] = '\0'; return dest; } |
#include int main () { int myArray[] = {5, 6, 7, 8}; int * myPointer = &myArray[0]; printf("Print address of beginning of array of 4-byte integers:\n"); // print address of myArray[0] printf("&myArray[0]:\t0x%08lx\n", (unsigned long)myPointer); printf("&myArray[0]:\t%p\n", (void*)&myArray[0]); printf("&myArray[0]:\t%p\n", (void*)myPointer); // print address of next element of the array printf("&myArray[1]:\t0x%08lx\n", (unsigned long)(myPointer+1)); printf("&myArray[1]:\t%p\n", ((void*)&myArray[0])+sizeof(int)); printf("&myArray[1]:\t%p\n", ((void*)myPointer)+sizeof(int)); return 0; } |
|
Trying to make a simple tic tac toe game and I'm stumped, something is not working right. The grid is drawn easily, but I can't alter the grid for some reason or printf the proper character after getting input. It's probably something very simple and stupid, but its been a long time since doing any programming. Code: #include /* draw ... |
rivkyfried1 Registered User Join Date Aug 2010 Posts 17 loading 2 character arrays in a row I am having a strange problem. I am attempting to load two character arrays in a row. The program then sends one of the arrays to a function called binarysearch. The code looks like this: Code: strcpy (irregverbs[0], "be"); strcpy (irregverbs[1], "bear"); strcpy ( irregverbs ... |
Hi, i am currently trying to write a program that can accept 3 input strings and perform different tasks based upon it. I currently have written a program that will scan what the user inputs and display how many characters have been inputted and also the amount of spaces to differientiate between strings. I have also set a limit to stop ... |
|
|
|
|
|
Hi guys, hoping you can help with an assignment I'm working on. I've got most of the program working, but it's just little bits and pieces that need tying up. Basically one part of the program requires the user to enter a character for the corresponding room type - so for a rectangular room, the user would enter R or r, ... |
Yeah sometimes it feels like that. If you are new you get flamed for what you don't know, if you are experienced you get everything you say compared to the most recent C/C++ standard all while your every thought is disected and critiqued by all. You just gotta learn no one has any hard feelings. We just try to keep one ... |
|
|
It seems as if someone else on here is doing the exact same assignment as me...haha...well...I have some different problems. If you run this, you see that, after you enter the word, you have to hit 10 times for the next "please enter your ## word" to come up. Its obviously effecting my results if you keep going through the ... |
|
|
Code: #include void printArray(char a[][2]); void modifyElement(char table[4][2]); void checkArrangement(char table[4][2]); int main() { char table[4][2]={'1','2','3','4','5','6','7','8'}; int counter=1; printArray(table); while(counter<=3){ modifyElement(table); printArray(table); counter=counter+1; } checkArrangement(table[0][0]); return 0; } void printArray(char a[][2]) { int i; int j; printf("\t_____U____\n"); for(i=0;i<=3;i++) { for(j=0;j<=1;j+=2){ printf("\t%c|\t|%c\n",a[i][j],a[i][j+1]); } } printf(" \t----------\n"); } void modifyElement(char table[4][2]) { int seat; int r; int c; char guest, junkChar; printf("In ... |
|
Hello all! I am hoping someone can help me with this because my professor wont get back to me(he lacks programming skills, I believe). Anyways, I am supposed to create an array with a user specified amount(between 10 and 30) of random letters to be generated. After the amount of characters has been specifed, the program should send the base address ... |
#include #include int exist (char *str, char c) { while (*str++) if (*str == c) return 1; return 0; } void add (char *str, char c,int *tmp) { int i; for (i=0; i<(*tmp); ++i) ; str[i] = c; } int main(void) { char str[100]; char curr; int tmp = 0; while ((curr = getchar()) != '\n') if (!exist(str,curr)) { ... |
|
I have been having trouble with using arrays of indefinite size. I havent had a problem I think creating an array of unknown size but I have had problems ending the program. I have noticed that others have had similiar problems but I am still unsure as to how I should go about fixing the problem. If I were to calculate ... |
|
help with character arrays Hi I've just started to learn c programming at college and I'm having a bit of difficulty in getting my head aroung character arrays.In the program I'm writing I need to be able to display a grid of 11 *11. This is made up with city names and distances. I read these from a text file which ... |
|
Ok, I am running into a brick wall so time to ask- I have a test driver. Up to this point it runs on one data file, but I wanted to make it able to run a series of tests. So I have made a file that contains the full names of all tests I want to run (e.x. c:\test1 c:\test2) ... |
|
#include #define MAXLINE 1000 /* maximum input line size */ int getline(char line[], int maxline); void copy(char to[], char from[]); /* print longest input line */ int main(void) { int len; /* current line length */ int max; /* maximum length seen so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line saved here */ ... |
Your program's first problem is that it is not being displayed inside of code tags. You can rectify that problem by editting your OP and placing [code] in front of your code listing and [/code] behind your code listing. Please do that now so that we may read your listing. I contest your assertion that your program only gave you 2 ... |
Hey guys, I'm having a little trouble figuring out how to do part of an exercise in my book. The user is supposed to enter in a sentence, in one line, and I'm supposed to printout each word (that is separated by a space) and also printout how many characters each word has. Oh, and it doesn't want us to use ... |
Quote: Originally Posted by lozware Thank you! Also, what do I use in C++ when I am refering to the NULL character? Do I simply write the word NULL in caps, or lowercase? My teacher writes it '\0' - does that mean it takes up 2 characters, or just 1. First, NULL is a pointer value and it is also called ... |
I want to take a string an add two characters in front of it. It sounded pretty simple, but I seem to have forgoten how to move a pointer to an array back and forth through its indeces. I think all I need to do is have two arrays. One with the string, and the other one with nothing in it ... |
Hi... I have some problem here.. hopefully somebody could help me... Actually i want to read some input as below :- Sequenced Value 100 123ABC 101 BVF122 102 KJNG098 103 C123XXX then stored into memory... then at the last of the program, I want to print out the Value based on Sequenced input. As example :- -> print C123XXX if the ... |
hi there! i have a function that retrieve data from a data base. then all of the retrieve data is then converted to a string (character array ) of data. i don't have any control on how many rows of data are retrieve from the data, so the problem is basically there is not enough space (don't know if this is ... |
I am not an expert C/C++ programmer, and am having a bit of a problem on a school assignment. The assignment is to build a text file based database. The program has to read a schema file containing information about the individual tables (table name, filename, data field name, type, and length). Then it must be able to read the data ... |
Hi Im having trouble with the following code/pseudo code and wondered if anyone can help. I need to take a binary message e.g. "10101010111111111111111" and split it into further binary messages such that each split binary message has 1 character less than some other binary message n. So for example if... b = 10101111000010101100 ie 20bits n = 10111 ie 5bits ... |
Yes, they can, as in: Code: char myCstring [] = "This is it"; This is a special case. The compiler finds memory for the array, initializes it, and gives you a pointer (myCstring) to it, thus satisfying the demand for a valid pair. Normally, the contents are not writable, they're const. For a writable string, do thusly: Code: char myCstring [someNumberHere] ... |
I'm having a brain freeze here, could someone help me out? I have the following code in a function Code: void name(Player sorter[], int count) { bool swap; char templast[50]; char tempfirst[50]; char temppos; int tempnum, tempreb, tempass, temppo; do { swap = false; for (int number = 0; number < (count - 1); number++) { if (strcmp(sorter[count].lastname, sorter[count + 1].lastname) ... |
in the following code, i am stuck and confused about how to bring 2 character arrays into one. what i want to happen, is for this registry path "Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users" to have things added on to it, so it will be like... "Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users\\SomeuserName" "Software\\America Online\\AOL Instant Messenger (TM)\\CurrentVersion\\Users\\TheNextUserName" etc.. please check out my getNumberAIMHashes() ... |
I assume you're using C, so the answer is no. Your best bet is realloc. The code will be something like this. { int maxsize = 10; int currsize = 0; char *x = calloc(size, sizeof(char)); while(input) { if(currsize==maxsize) { maxsize = maxsize * 2; x = realloc(maxsize, sizeof(char)); } // Get the next char currsize++; } something like that should ... |
I have a character array RIB which is a part of a structure REL that is typedef struct { char JUNK[17], char RIB[3] } REL In my code I have an instance (maybe it is wrong to use that word in C but I come from a Java background) REL rel; Now I want to print the the first character of ... |
and you asked me about the index value in for loop: i use "j=name[i];" the reason is if you give "j=0; then it will print whatever i scanf as you say will print from 0 to name[i] (40 times or 50 time) i the the limit of my character array. thanks again |
I' working on an array where the user inputs characters(up to 80). I then need to output the characters, one per line, until the string is null. My problem is in the while loop i think, im just not sure what to do from here. Any ideas? 1. #include 2. void main() 3. { 4. char chararray[80]; 5. int n ... |
/***** required macros and structures *****************/ union example { char array[6]; struct ints { short a; short b; short c; }x; }; union example e1; #define swapbytes(z) (((short)(z << 8)) | ((short)(z >> 8))) /********************example code snippet ****************/ int main(int argc, char* argv[]) { memcpy(e1.array,"aBCDEF",6); printf ("value of array = %s\n",e1.array); printf("value of a = %X\n",swapbytes(e1.x.a)); printf("value of b = %X\n",swapbytes(e1.x.b)); ... |
I am wondering if I can compute a one-to-one mapping from a series of types to characters using metaprogramming. I currently have a template with a list of types such as T1, T2, ..., T15. My code fills a character array with I-th position filled based on the I-th type. I am wondering if I can compute the character array at ... |
I have a 1-D character array of over 64,000 bytes. I want to break this array into a 3-D character array. Each element would be 32bits(4bytes). What would be the easiest way to do this?The original character array is the character representation of a 32-bit per pixel bitmap image. The information for each 32-bit pixel is just ... |
Hello,Disclaimer: I am trying to do this for a homework assignment, so please do not outright tell me how to code my solution.I have been tasked by my instructor to write a function that compares string1 with string2. I am to take out of string1 whatever is not in string2.Noting the various functions in the string.h library, I could not ... |