Digits
Consider the following header file:
myheader.h
#ifndef _MYHEADER_H
#define _MYHEADER_H 1
void foo(char *, const char *);
#endif /* myheader.h */
download as text file
Write the foo()
function declared in myheader.h
that takes the address of two strings as parameters. The function should concatenate the digit characters in the second string into a single string and store this string at the memory location pointed to by the first parameter.
Note
Place the function in a file named foo.c
and submit this file as a solution to the evaluation system. You can test your solution using the following files. The evaluation system does not necessarily perform the evaluation using these files.
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "myheader.h"
int main()
{
char source[100], destination[100];
while (fgets(source, 100, stdin) != NULL)
{
if (source[strlen(source) - 1] == '\n')
source[strlen(source) - 1] = '\0';
foo(destination, source);
printf("%s\n", destination);
}
return EXIT_SUCCESS;
}
download as text file
Makefile
SRCS = main.c foo.c
OBJS = $(SRCS:%.c=%.o)
TARGETS = main
.PHONY: clean
all: $(TARGETS)
main: $(OBJS)
$(CC) $(OBJS) -o main
%.o: %.c
$(CC) -Wall -c $< -o $@
clean:
rm -rf $(OBJS) *~ $(TARGETS)
download as text file
Sample Input
A1B2C3
ABC123
ABCDEF
123456
download as text file
Output for Sample Input
123
123
123456
download as text file
One possible solution is available in: main.c.
Acknowledgement
This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.