First mistake
should be
if you want to copy a string into it.
The lines
write past the end of your arrays.
You also need to change the formatting in the printf; it should be
Jim's solution covers all of this but does not ensure that the strings in part_one and part_two are null-terminated:
sets only the first element to 0.
I would use strncpy(3) instead which pads out any remaining space in the destination array with nulls.
spirtle -
According to C99 standard all of the 10 elements of x are set to zero. Unless you are using ancient Solaris compilers or something.... try it with this junk code in debug mode: edit: see para 21 in section 6.7.8 of C99 standards.
break on the line # for /* this point */
Last edited by jim mcnamara; 09-12-2008 at 06:31 PM..
Reason: couldn't find reference got it now
I need do pass these variables to some other fn like this
db_insert_last_log_name(char *model,int number)
If you are going to pass numerics as an int then in the example the number part of the logical name will go from 00001 to 1 as leading zeros will be removed from an int. Is that what you want or do you want to pass a numerical string --> 00001 ??
Here are two programs that pass a pointer to a variable but behave differently. Shouldnt the i in second program be 0 after the function call?
#include<stdio.h>
void changeI(int *i)
{
*i = 10;
}
int main(void)
{
int i=5;
printf("%d before\n", i);
changeI(&i);
printf("%d... (1 Reply)
Does anyone know?
int x = 1;
int *p = &++x; //ok !
int *q = &x++; //gives an error :O
why the first pointer is ok but the second is an error? (13 Replies)
Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It.
Can someone help?
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int f1(char **str_);
int main(int argc, char **argv)
{
char *str = NULL;
f1(&str);
... (3 Replies)
Hi,
Can anyone tell me how i can declare and allocate dynamically an array of pointers to structured type?? Is declaration something like this:?
struct_name ** array; (1 Reply)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
can u tell me the reson that why we should not delete a pointer twice.?
if we delete ponter twice then what happen and why this happen
Regards,
Amit (2 Replies)
void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)