473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

strcat help

Hi All,

I am new with c and would like some help.
When reading a bin file the year is 06, the decimal value = 6 so I use the &rawtime to determine the year and then
cat it with the array (xya[j]) so that the result will printf 2006 and do this with the month as well as the day.
How can I strcat the "strncpy(datum,(char *)(ctime (&rawtime))+20,3);" (200) with the xya[j] array??????
Whenever I compile with gcc there are errors :
C.Fopen.c:170: warning: passing arg 2 of `strncat' makes pointer from integer without a cast
oC.Fopen.c:170: too few arguments to function `strncat'

What am I doing wrong or is there any other way to do this.

if(length < 10)
{
time (&rawtime);
if (xya[j]<10)
{
strncpy(datum,(char *)(ctime (&rawtime))+20,3);
datum[3]='\0';
}
else
{
strncpy(datum,(char *)(ctime (&rawtime))+20,2);
datum[2]='\0';
datum[3]='\0';
}
printf("XXXXX %s XXXXXX",datum);
strcat(datum,xya[j]);
// cat 200 with xya[j] (6) = 2006
}
//printf(" %d Len",length);
//printf("%x",xya[j]);
//printf(" Len %d ",length);
Jun 4 '06 #1
1 5051
Banfa
9,065 Expert Mod 8TB
Some points
  • The compiler error given talks about errors calling strncat but you seem to be calling strncpy and strcat. Have you posted the code you compiled?
  • (char *)(ctime (&rawtime))+20 there is no need for this cast ctime returns char * so this can be written as (ctime (&rawtime)+20
  • datum[2]='\0';
    datum[3]='\0';

    For normal string processing there is no need to set the characters after the first null terminator to anything, setting datum[3] here is not required.
  • strcat(datum,xya[j]); Since you have not posted the type of xya it is not possible to know exactly what the problem is. However the prototypeof strcat is
    char *strcat( char *strDestination, const char *strSource );
    so xya[j] must have type char *, this means that xya must be declared either as
    char *xya[N];
    or
    char xya[N][M];
    Where N and M are constants. From the error message and code I suspect that xya[j] has an integer type, may be declared as
    int xya[N];
    If this is the case then you will need to convert that integer to string first using either sprintf or some code of your own devising.
Jun 5 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Patrick Coleman | last post by:
Hi, I have the following code: char request = "GET "; strcat(request, path); //Path is the path section of a url ie. "/path/test.htm" strcat(request, " HTTP/1.1"); cout<<request<<"\n";...
5
by: Ian Stanley | last post by:
Hi, Having not done any C programming for a while I am trying to get back into it by converting an old java assignment into C. The problem is I am getting a segmentation fault at runtime which I...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
23
by: JC | last post by:
hi, i want to combine two string together.. and put in to another string. how can i do . i try myself.. with the follow code. but seem can't get the result i want.. i want to get the result with...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
9
by: cicalese | last post by:
For starters, I am a C novice. I don't fully understand how strings work. I am running on a linux box. I compile w/ gcc. I have a string called 'myabqcommand' that is being overwritten when i use...
16
by: Lilith | last post by:
I'm working on a simple piece of code under VC++ 6.0. I've got a char Buffer array into which I copy the contents of an MFC control. The string is properly nul terminated. I use strcat (Buffer,...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
4
by: nick048 | last post by:
Hi, I have this problem: int n; char nToChar; char firstString = "The number is: "; char resp; /* HERE MAIN WITH THE INPUT OF n*/
1
by: Frusciante | last post by:
Hi! I wanted to thank you a lot for the help given yesterday... It`s so great to have people so well prepared trying to help you! I have another problem: the bold line : strcat want a pointer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.