Hi all,
Can anybody please tell me how can I put dot(.) in a string using C programming.
for example --
I am having string "10111988" and I want to convert it as "10.11.1988"
I will appriciate and thanks in advance..
Hi all,
Can anybody please tell me how can I put dot(.) in a string using C programming.
for example --
I am having string "10111988" and I want to convert it as "10.11.1988"
I will appriciate and thanks in advance..
Hi
#include<stdio.h>
#include<string.h>
int main()
{
char a[11]="10111988";
char b[11];
int i,j=0,len;
printf ("The input is :<%s>\n", a);
len=strlen(a);
for(i=0;i<len;i++){
b[j++]=a;
if (i==1 || i==3) {
b[j++]='.';
}
}
b[j]='\0';
printf ("The o/p string is <%s>\n",b);
return 1;
}
On running this:
The input is :<10111988>
The o/p string is <10.11.1988>
Hi ,
I am getting input from string data[0].first.last(10 char) and when I am trying to apply above code,
and after running, I am getting input as null value.
Thanks in advance..
Hi
You need to use strcpy to copy strings:
strcpy(a,data[0].first.last);
Guru.
SEGV waiting to happen:
char a[11]="10111988"; // 10 chars, fits in 11 bytes with terminating NUL.
char b[11]; // 11 bytes can't hold 12 chars plus terminating NUL
And
strcpy(a,data[0].first.last);
Without data validation, another potential SEGV. Or potential security hole.