Quote
at the low digit, and concatenating those digits. *
Examples:
everyNth(12345, 1) = 12345
everyNth(12345, 2) = 135
everyNth(12345, 3) = 25
everyNth(12345, 4) = 15
everyNth(12345, 5) = 5 *
Pre: Value and N have been initialized and N is greater than zero.
Post:
Returns: integer value formed by concatenating the specified digits of Value; if N = 0, the return value is undefined *
Restrictions:
1. You may use any integer operations supported in C.
2. You may also use any selection (if, if..else, etc) or iteration (for, while) constructs.
3. You may not use an array, nor may you perform any I/O operations.
I have used the following code:
#include "everyNth.h"
uint64_t everyNth(uint64_t Value, uint8_t N) {
uint64_t Accum;
while(Value)
{
Accum = strcat(Value, N));
}
return Accum;
}
But am getting errors.
Quote
everyNth.c: In function `everyNth':
everyNth.c:8: warning: implicit declaration of function `strcat'
everyNth.c:8: warning: passing arg 1 of `strcat' makes pointer from integer without a cast
everyNth.c:8: error: too few arguments to function `strcat'
everyNth.c:8: warning: assignment makes integer from pointer without a cast
Any tips? I'm following the example in the book exactly (or so I thought).
everyNth.h is
#ifndef EVERYNTH_H #define EVERYNTH_H #include <stdint.h> /////////////////////////////////////////////////////////////////////// // // Forms an integer value by taking the Nth digits of Value, starting // at the low digit, and concatenating those digits. // // Examples: // everyNth(12345, 1) = 12345 // everyNth(12345, 2) = 135 // everyNth(12345, 3) = 25 // everyNth(12345, 4) = 15 // everyNth(12345, 5) = 5 // // Pre: Value and N have been initialized. // N > 0. // Post: // Returns: integer value formed by concatenating the specified // digits of Value; if N = 0, the return value is undefined // // Restrictions: // You may use any integer operations supported in C. You may also // use any selection (if, if..else, etc) or iteration (for, while) // constructs. // You may not use an array, nor may you perform any I/O operations. // uint64_t everyNth(uint64_t Value, uint8_t N); #endif
and driver.c is as follows:
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include "everyNth.h"
void testEveryNth();
int main(int argc, char** argv) {
testEveryNth();
return 0;
}
void testEveryNth() {
uint64_t Value = 12345;
uint8_t N = 2;
uint64_t Result = everyNth(0, N);
printf("%21"PRIu64"%3"PRIu8"%21"PRIu64"\n", Value, N, Result);
}
This post has been edited by CoryMore: 12 October 2012 - 09:21 PM

New Topic/Question
Reply



MultiQuote





|