473,738 Members | 3,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strcat help

4 New Member
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,xy a[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 5075
Banfa
9,065 Recognized Expert Moderator Expert
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))+2 0 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,xy a[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
5455
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"; //This outputs "GET /path/test.htm HTTP/1.1" happily //Send packet (I know there's no error checking, this is just an example)
5
4640
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 am having trouble fixing(program below) The idea of the program is to convert input(integers) into words eg: # 101 returns #one hundred one I have found the problem is with the strcat of the strings & literals --
18
6174
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 strcat (mystract). Program below. However this appears not to have fixed the problem and I don't know why it shouldn't ? Any further help as to what else I am doing wrong will be appreciated regards
23
11610
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 "c is abcd" . #include <stdio.h> #include <string.h> void main() { char a="ab"; char b="cd";
81
7323
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 be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
9
3430
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 strcat() on some unrelated strings. For this code: char *myabqcommand; myabqcommand = strtok(x, "-");
16
5164
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, "\r\n") to append a carriage return\line feed to the string before outputting it to a display where I can monitor what's being exchanged with another service. But after the strcat the string in Buffer is terminated, not with \r\n but with a \n...
87
5141
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 the library, and other resources related to managed strings are available for download from the CERT web site at: http://www.cert.org/secure-coding/managedstring.html
4
4709
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
1804
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 as argument, but probably i'm mistaking it ... can anybody help me? #include <stdio.h> #include <string.h>
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.