The standard library is your friend here - look for 'strlcpy'
Without error checking, it should look something like this...
// START CODE
// we need an extra char
// for the null character at the end - so we need j + 1 chars
char * s2 = malloc( sizeof(char) * (j + 1 ) );
strlcpy( s2, s1 + j, j + 1 );
// END CODE
Hope this helps.
EDIT:::::::
Oops... strlcpy is not actually part of the C standard library... :(
It ought to be kicking around on most Linux distros...
If your environment does not provide strlcpy, use its cousin, strncpy
to do this with strncpy... (strncpy has poorer error handling than
strlcpy imo, but they operate very similarly)
// START CODE
char * s2 = malloc( sizeof( char ) * ( j + 1 ) );
strncpy( s2, s1 + j, j + 1);
s2[j] = '\0'; // strncpy does not guarantee a null-terminated result :(
// END CODE
Hope this helps - and isn't broken ;)
What is the application of regular expression in compiler construction?
Regular Expression is another way of implementing a lexical analyzer or scanner.
How much void point do i need for full void?
runescape question: 850 pest points, You can get these by playing pest control. You have to be a member though.
How do we get values through pointers instead of arrays in c?
If the pointer is pointing to an array, you would do the exact same and use [], but if it weren't pointing to an array, you can use * to extract data from the pointer.
eg:
int a = 5; //set a to 5
int* b = &a;//set b to the address pointed by b
int result = *b; //extract data b is pointing to (5)
result would then be 5
What is the order of initialization of data in C plus plus?
The general order of initialization is:
Statements are composed from expressions. A semi-colon turns an expression into a statement.
A function is not a statement it is a type definition.
A statement block is a compound statement, one or more statements delimited by braces, {}.
A function block is the body of a function. The body must be enclosed in braces, {}.
How do you work with video memory in c?
Video memory is hardware specific. Any c implementation that directly accesses video memory will not be portable. In fact, video memory will probably not be accessible in modern operating systems, because the video driver provides the interface. Also, even the same hardware has different addresses for different modes.
It is better to use the OS's API to drive the image.
It you must access video memory, and assuming that you can, such as in real mode DOS, you can define a pointer unsigned char *ptr and initialize it to the address of video memory such as ptr = 0xB0000 and then use it ptr[someaddress] = somevalue. Keep in mind that you will probably also need to interface with the hardware registers.
It is better to use the OS's API to drive the image.
It is better to use the OS's API to drive the image.
Am I being clear enough? :-)>
Logic circuit that converts four digit Binary Input into Binary Coded Decimal?
Design a logic circuit that converts a four digit binary input to equivalent Binary Coded Decimal value. You need to first create the truth table (please note this circuit should have four input bits, but five output bits; for example, for an input 1001 (decimal 9) the suggested output will be 0 1001 (the BCD value 0 9); and for an input 1010 (decimal 10) the suggested output should be 1 0000 (the BCD value 1 0 )). After creating the truth table design the Boolean expressions for each of the five output bits. Draw the resulting circuit diagram using AND - OR - NOT gates.
What types of loop may not execute at all?
One in which the condition is evaluated at the beginning. Details vary from language to language; for example in Java, this may be the case both with a for loop and with a whileloop.
Why don't ReactOS developers focus on getting their operating system to run on real hardware?
ReactOS has few developers, which makes tracking down issues on real hardware much more difficult. For this reason, only virtual machines are targeted. ReactOS is not meant to be useful at this point in time, so it makes no difference on whether it runs on real hardware or not (which it actually usually does). A technically correct implementation is more important at this time than a functional one.
Dynamic carts helps with demonstrating and experimenting laws of dynamic. They provide tool samples to help with the demonstrations and experiments.
Algorithm to convert a number representing radix r1 to r2?
algorithm to convert a number representing radix r1 to radix r2
How does one indicate that certain text is to be treated as a comment in the classic C language?
Place the text between /* */ .
What is accumulator function in c language?
Normally the return value from the function is through the information
from the accumulator.
a leniar datastructute is one in which the oragnisation of data can be done in a linear manner i.e each element may consist of one predicessor and one succsor.
eg:stacks queus,linked lists
What is the average efficiency of heapsort?
The efficiency class is O (n log n).
See the related link for further information.
Loops are very important part of a C-language.
If we have to run our programe multiple time then we use Loops of C.