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);
1 5071 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. Sign in to post your reply or Sign up for a free account.
Similar topics |
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)
|
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 --
|
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
|
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";
|
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
| |
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, "-");
|
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...
|
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
|
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*/
|
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>
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |