Adding two character pointer


How to add two character pointer value

Eg:
char *a = "10";
char *b = "20";
char *d ;
Here i need to add the value of a and b ie., 10 +20 = 30
and have to store it in d.
But when i do (d = (int)a + (int)b ) i am getting an
error.

so please help me how to add a and b value. and store it in d.
At last how to print the value of d.

Please help me in this issue

Posted On: Monday 5th of November 2012 12:53:30 AM Total Views:  300
View Complete with Replies

RELATED TOPICS OF C Language PROGRAMMING LANGUAGE




program adding numbers using desired base doesn't show any output

, I have a problem with an "add calculator". Valgrind reports no memory errors, no errors from compiler but the program doesn't show any output despite the printf - "Result is zero". pointers, and variables are (n my opinion) correctly initialized. getnum function gets a number, returns a pointer to char *, add function processes two numbers as strings, returns result which is a pointer to char (char *) as well. Trying to work it out for the past 4 hours and can't find a mistake.
VIEWS ON THIS POST

136

Posted on:

Saturday 22nd September 2012
View Replies!

adding a loop

how would I add a loop that would instruct a user to enter a pair of 00 to end a loop Code: #include int main() { int x; // will define first number int y; // then the second number printf( "Please enter first number: " ); // prompt scanf( "%d", &x ); //read first integer printf( "Please enter second number: " ); scanf( "%d", &y ); // read second integer // compare the two numbers if ( x > y ) { printf( "%d is larger\n", x ); } if ( x < y ) { printf( "%d is larger\n", y ); } if ( x == y ) { printf( "These numbers are equal\n" ); } return 0; }
VIEWS ON THIS POST

185

Posted on:

Monday 1st October 2012
View Replies!

Help adding leading zero's to a char!!

Hi all; I basically want to add leading zero's to a char when going from int to a char in snprintf. See example : Code: unsigned char len[2]; int length = 144; snprintf(len, 2, "02%d", length); /*this would add leading zeros to the integer*/ snprintf(len, 2, "02%c", length); /*this doesnt work for a char, any ideas
VIEWS ON THIS POST

178

Posted on:

Thursday 4th October 2012
View Replies!

adding text from file to a linked list

i am trying to add words from a text file to a linked list. my code works fine , but if the text file is too big it shows the following error: stack smashing detected. Can anyone help me please here is my code Code: #include #include #include #include FILE *f; int wordc=-1; struct list { char *str; struct list *next; }; struct list *root; struct list *head; struct list *curr=NULL; int init_list(){ root=(struct list *)malloc(sizeof(struct list)); head=root; if(root==NULL ){ printf("Init list failed\n"); return(1); } root[0].next=NULL; return(0); } int list_add(char string[],int wordc){ struct list *curr=(struct list *)malloc(sizeof(struct list)); char *str1; if(root==NULL ){ printf("Add list failed\n"); return(1); } str1= (char *)malloc(60*sizeof(char)); strcpy(str1,string); curr->str=str1; if(wordc==0) head->next=curr; else root->next=curr; curr->next=NULL; root=curr; } void print_list(){ struct list *ptr; ptr=head; while(ptr!=NULL){ printf("|%s|\n", ptr->str); ptr=ptr->next; } printf("\n"); } int open_file(char fname[]){ FILE *f; char ch; char buf[60]; int i=0; f=fopen(fname,"r"); if ( f== NULL ){ printf("ERROR OPENING THE FILE\n"); return(1); } //word count do { if((ch=fgetc(f))==EOF) break; do{ buf[i]=ch; i++; }while((ch=fgetc(f))!='\n'); buf[i]='\0'; wordc++; printf("1\n"); list_add(buf,wordc++); i=0; printf("2\n"); }while(1); } int main(int argc,char *argv[]){ if(argc!=2){ printf("wrong parameters\n"); return(1); } init_list(); open_file(argv[1]); print_list(); }
VIEWS ON THIS POST

208

Posted on:

Saturday 6th October 2012
View Replies!

Please Help!!! Why corrupted stack - in C - adding an array of int and passing

Following is the code and I am not sure why I get the stack error!!
VIEWS ON THIS POST

244

Posted on:

Wednesday 17th October 2012
View Replies!

Efficiently adding to the end of a linked ist

, I have a code that works fine, but I have a question about efficiency. Here is a snippet of my code Code: void insert_at_end ( listNode * ptr, int data ) { listNode temp; temp=*ptr; if(*ptr==NULL) { temp=malloc(sizeof(lNode)); temp->n=data; temp->next=NULL; *ptr=temp; return; } while(temp->next!=NULL) { temp=temp->next; } temp->next=malloc(sizeof(lNode)); temp->next->n=data; temp->next->next=NULL; temp=temp->next; } What this does it gets the head of the linked list, goes until the end, and then tacks on another node. I noticed that this has O(N) complexity, and will be super inefficient if I have a large list(like a billion nodes or something). Is there a more efficient way of adding at the end, WITHOUT using a tail pointer I know it could be done in O(1) time with a tail pointer, but I'm not sure I'll be able to use tail pointers in labs and such.
VIEWS ON THIS POST

258

Posted on:

Wednesday 17th October 2012
View Replies!

C Structure Padding

Anyone know where is the reference of C Structure Padding I mean, how do they pad data inside a structure
VIEWS ON THIS POST

172

Posted on:

Tuesday 23rd October 2012
View Replies!

adding timeval's

I'm trying to add the current time + a randomly generated time w/ millisecond precision, but the numbers aren't making sense. If I add rand_time + now_time on my calculator, I get a different result than what's in sched_time. Anyone see what I'm doing wrong These are my results .. rand_time = 4958.128418 now_time = 1225033344.000000 sched_time = 1225038336.000000 (my calc says rand_time + now_time = 1225038302.13) struct timeval now; gettimeofday(&now, NULL); float rand_time = random_time(); float now_time = now.tv_sec + (now.tv_usec / 1000000.0); float sched_time = now_time + rand_time; printf("rand_time = %f\n", rand_time); printf("now_time = %f\n", now_time); printf("sched_time = %f\n", sched_time); float random_time() { int const MAX_MILLISECONDS = 5000; return (rand() / (RAND_MAX + 1.0) * MAX_MILLISECONDS); }
VIEWS ON THIS POST

194

Posted on:

Sunday 4th November 2012
View Replies!

Padding bits and char, unsigned char, signed char

Under C++03: Is it guaranteed that char, unsigned char, signed char have no padding bits
VIEWS ON THIS POST

223

Posted on:

Sunday 4th November 2012
View Replies!

adding alignment support n2140 & n2165 inconsistent alignment value calculation

===================================== MODERATOR'S COMMENT: Apologies for the delay in moderation; this appears to be caused by my ISP (Cox) dropping and/or blocking e-mail. ===================================== END OF MODERATOR'S COMMENT Sorry if the following appears more than once. I sent it but got no response in 24 hrs; so, I'm resubmitting. --- original message: --- According to the table on: http://www.open-std.org/jtc1/sc22/wg...mailing2007-03 the document: http://www.open-std.org/jtc1/sc22/wg...2006/n2140.pdf is the predecessor to the document: http://www.open-std.org/jtc1/sc22/wg...2007/n2165.pdf According to n2165, page. 10, aligned_storage::alignment_value is: the least common multiple of all Alignments However, according to n2140, page 5, aligned_storage::alignment_value is the "largest digit that is set" in "the binary-ors all Alignments". I can understand n2165; however, I don't understand n2140. The largest bit set is a number from 0 to 31 on a 32 bit machine. So, if the only element in an aligned_union is an int, with alignment 4, then the largest digit set of binary-or of 4 is 2, and 2 is the wrong alignment for an int. OTOH, if n2140 meant 2 raised to the power of the largest digit that is set, then it would make more sense, but this, AFAICT, would not be the same as the least common multiple. So, is n2140 wrong In addition, if all alignments are 2 raised to some unsigned power (as required by paragraph 4 on page 5 of n2140) then wouldn't the max of all alignments give the correct alignment for the union OTOH, if the extended alignments (page 3 of n2165) were allowed, then least common multiple instead of max would be the correct method for calculating the composite (union) alignment. So, is lcm instead of max used on page 10 to accommodate extended alignments TIA. --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
VIEWS ON THIS POST

221

Posted on:

Sunday 4th November 2012
View Replies!

Remove first two characters from char* or from int?

I have a char *year that contains a 4-digit year (i.e 1929), I use the following syntax c = atoi(year); to convert it to an integer. However I must strip the first two numbers. I've tried to convert it from char* to a string and use the erase function, which works, but then I can't seem to convert the string it to an integer. I am impartial as to when I remove the first two digits, meaning it can be done before or after the conversion to int. In my example above the end result should be an integer variable equalling 29. , yogi_bear_79 wrote: >> c = atoi(year+2); > Perfect!
VIEWS ON THIS POST

276

Posted on:

Sunday 4th November 2012
View Replies!

Re: Check whether two functions are compatible using metaprogramming.

On 19 fev, 10:59, Thomas Lehmann wrote: > 2) Meta programming. I just want to know wether two types > are the same or not! Unfortunately that's not what I really meant by using two functions interchangeably. If you make a string comparison of, say, void(*) (double) and int(*)(int), your metafunction will say that they're (rightfully) different. But say I have: int test(int a) { return a; } std::function> f = a; It is valid and compiles, although the function signatures are different. I want a metafunction that tells me whether we can set a particular std::function to another function which signatures are different, but 'compatible', as is in this case. My real issue is with function overloading. Suppose I have two functions: void func(std::function f) {} void func(std::function f) {} The correct overload would only be resolved if the parameter I'm passing is a std::function with the correct signature. If I pass, for instance, a 'int test(int) {}' pointer to func, instead of resolving to the first overload, the compiler will say the call is ambiguous. I want to disambiguate this by using SFINAE, by removing the unwanted overload from the overload set.
VIEWS ON THIS POST

174

Posted on:

Sunday 4th November 2012
View Replies!

[HALF-OT] Separe two channel with direct-sound...

I capture audio (stereo) data with directx 9 with c++. I would like to separe the two channel and process they separately. But I not able. How are put the sample on buffer that directx give me on notify function I have a array of BYTE, which of this BYTE are of a channel and which other channel How the information are subdivide on this buffer Someone can help me
VIEWS ON THIS POST

146

Posted on:

Sunday 4th November 2012
View Replies!

Executing applications across a network (possible OT)

Sorry for cross-posting; I'm not sure which group would be more appropriate, if any. At present I have 2 applications (installed on the same workstation): (A) is the main application which is running most, if not all, of the time. Only one instance of (A) can be running at once. (B) is an application which send messages to (A). These messages instruct (A) on what data files to process. This is achieved by calling (A) with ShellExecute(), passing arguments specifying the location of a data file (this data file could be any file over the network of workstations). When (A) receives these arguments, it adds the data file to it's list of jobs to process. The above process has been working well. Data can be accessed and processed anywhere on the network. The downside is the operators can only "send" data from one workstation. What I now want to do is install (B) onto all workstations in the network. Does ShellExecute() work over a network If not, how to get around this What other methods can I use to notify (A) of jobs to process
VIEWS ON THIS POST

147

Posted on:

Sunday 4th November 2012
View Replies!

Re: AND Operation on a two dimensional array

"Diego Martins" wrote in message news:8906da9e-2e1d-4215-a756-685f4df08566@q39g2000hsf.googlegroups.com... > On Jan 12, 12:06 am, "Howard" wrote: >> "Diego Martins" wrote in message >> >> news:204774a2-c46c-4eca-9437-648cc7ebfe20@j78g2000hsd.googlegroups.com... >> >> >> >> > On Jan 11, 2:26 am, Ivan Novick wrote: >> >> On Jan 10, 6:26 pm, Mugunth wrote: >> >> >> > What is the most effective way of implementing an AND operation on a >> >> > two-d array. >> >> > I've an array like, >> >> > 1 3 5 6 7 >> >> > 2 4 5 6 1 >> >> > 8 6 4 9 2 >> >> > The result should be another array that contains only 6. >> >> >> It seems like you are trying to find a list of numbers which are in >> >> every row of the 2-D array. Is that so >> >> >>
VIEWS ON THIS POST

99

Posted on:

Sunday 4th November 2012
View Replies!

problem in adding array elements

Hi. Pls help me i have the following code which is having error.This program is being written by Visual studio 2005 Pls help me ASAP. #include "stdafx.h" void fun(int); int arr[10] = {1,2,3,4,5,6,7,8,9,10}; int _tmain(int argc, _TCHAR* argv[]) { fun(arr[0]); return 0; } void fun(int *var) { int a = *(arr[0]+2); int b = *(arr[0]+3); int c; c = a+b; printf("\n %u",c); } Now the error is : illegal indirection
VIEWS ON THIS POST

158

Posted on:

Sunday 4th November 2012
View Replies!

Earn 7000 dollars in two weeks!!!! It really Works!!!

The Message: IF YOU DO THIS YOU WILL MAKE $7,000. HELP ME AND YOURSELF. GUARANTEED-you WILL have $7,000 in two weeks ONLY $5 TO $14 Total Cost, 1 HOUR OF WORK and NO MAILING LISTS "GIFTING CLUB" PLEASE READ TO FIND OUT HOW! If you want to make a few thousand dollars really quickly, then please take a moment to read and understand the program I am sharing with you. NO, it is Not what you think! YOU DO NOT have to spend $5 to five people to buy a report, get on their mailing list, OR buy a recipe or any other product. NOR will you need to invest more money later to get things going. This is the fastest, easiest program you will ever be able to do. Complete it in One hour and you will never forget the day you first received it in the mail or online. If you are doing other programs, by all means stay with them. The more the merrier! But Please read on. First of all, there are only three levels, not four, five or six, like many other programs. This three level program is more realistic and much, much faster. Because it is so easy, the response rate for this program is Very high and Very fast. And you receive your reward in about fourteen days. That's only Two weeks - not three months. Just in time for next month's bills!!!!!!!!!!! HERE ARE THE SIMPLE DETAILS You mail our 20 copies (not 200 or more as in other programs) or post 20 on the internet. You should send them to people who send you their programs, because they are already believers and your program is better and faster or post them in chat forums or on message boards. Even if you are already in a program, continue to stay with it, but do yourself a favor and DO THIS ONE as well. RIGHT NOW! It is simple and takes a very small investment, not hundreds of dollars. And it will pay you before the other letters even begin to trickle in!! Just give one person $5. That's it! That's all! Follow the simple instructions and in two weeks you should have at least seen $7,000 because most people will respond due to the low investment, speed, and huge profit potential. We are now at a 50% response rate! That's a $10,000 return. So let's all keep it going and help each other in these tough times. 1. On a blank sheet of paper write your name and address clearly and fold it around a five-dollar bill. Send this to the first name on the list. Only the first person on the list gets your name and a five- dollar gift. 2. Retype the list only, removing the first (#1) name from the list. Move the other two names up and add your name to the list in the third (#3) position. 3. Paste your newly typed list neatly over the old one and make 20 copies of this letter and send to 20 prospects or post 20 on the internet on message boards or chat forums. An excellent source of names is the people who send you other programs, and the names listed on the letter that they send you. Do it right away. It's so easy, Don't mull it over, One hour! That's it! There is no more to do. When your name reaches the first position in a few days, it will be your turn to collect your gifts. The gifts will be sent to you by over 1,500 to 2,000 people like yourself who are willing to invest $5 and one hours to receive $7,000 in cash. Your entire investment will be about $5 to $14 including the $5 gift you sent the first name on the list, envelopes, copies, and stamps. That's all! There will be a total of $7,000 dollars in your mailbox in $5 bills in two weeks. Consider that! CAN I DO IT AGAIN OF COURSE, No mailing lists to buy and wait for. No further trips to the printer or copier. And now you can do it again over and over with your regular group of gifters. Why not It beats working! Each time you receive a MLM offer in the mail, respond with This letter! Your name will climb position at a Dizzying geometric rate. I just spent two weeks in Manhattan at the Plaza seeing every show and attending every concert I wanted to and I haven't worked in three months. Some people may want to purchase a mailing list of opportunity seekers and send out 200 or more. That's fine. You can if you want to. That decision is yours to make. The possibilities are great. But we are enjoying a 50% rate to this letter. Not interested C'mon you have nothing to lose! Experimentation One hour of your time and about $12 to $14! ACT FAST AND GET MONEY FAST HONESTY AND INTEGRITY MAKE THIS PLAN WORK COPY THE NAMES CAREFULLY AND SEND FIVE DOLLARS TO THE FIRST NAME ON THE LIST! DO UNTO OTHERS AND ENJOY YOUR MONEY!! 1.TONY STARKS 2206 TANGLEWOOD DR. KINSTON, NC 28504 2.CALEB HIERS 3761 PINE BROOK DR. ACWORTH, GA 30102 3.MARK HOLSTON PO BOX 1908 GAYLORD, MI 49734
VIEWS ON THIS POST

141

Posted on:

Sunday 4th November 2012
View Replies!

sum of two integers

Hi everybody I have a problem which is puzzling me it is the following: Write a C++ program to find the sum of two integers without using any arithmetic, loops, recursions nothing.
VIEWS ON THIS POST

247

Posted on:

Sunday 4th November 2012
View Replies!

AND Operation on a two dimensional array

What is the most effective way of implementing an AND operation on a two-d array. I've an array like, 1 3 5 6 7 2 4 5 6 1 8 6 4 9 2 .. .. .. The result should be another array that contains only 6. Any ideas
VIEWS ON THIS POST

107

Posted on:

Sunday 4th November 2012
View Replies!

Calculate word from two bytes

Ouch. I see it. Stupid. /* THE INLINE FUNCTION getWord */ char getWord( char HiByte, char LoByte){ return ((HiByte & 0xFF)
VIEWS ON THIS POST

103

Posted on:

Sunday 4th November 2012
View Replies!