S
SysSpider
Hi guys,
I made a program in C (command-line) that prints a character the
number of times indicated by the user. But, when I insert '*'
(asterisk) as character, it says to me that I've insert more than one
character. With '&' (ampersand), it gives me an error. I have no clue
with '*', but I think the problem with '&' is related to pointers.
---Source code of chars2.c---
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i, n;
if(argc < 3)
{
printf("\nSyntax: chars2 <n> <char>\n\n");
printf("<n> - number of characters to be printed\n");
printf("<char> - character to be printed\n");
exit(0);
}
n = atoi(argv[1]);
if(strlen(argv[2]) > 1)
{
printf("Insert only *one* character, please\n");
exit(0);
}
for(i = 1; i <= n; i++)
{
printf("%s", argv[2]);
}
printf("\n");
}
---End of source code---
If anyone can help me, please reply.
Thanks,
SysSpider
I made a program in C (command-line) that prints a character the
number of times indicated by the user. But, when I insert '*'
(asterisk) as character, it says to me that I've insert more than one
character. With '&' (ampersand), it gives me an error. I have no clue
with '*', but I think the problem with '&' is related to pointers.
---Source code of chars2.c---
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i, n;
if(argc < 3)
{
printf("\nSyntax: chars2 <n> <char>\n\n");
printf("<n> - number of characters to be printed\n");
printf("<char> - character to be printed\n");
exit(0);
}
n = atoi(argv[1]);
if(strlen(argv[2]) > 1)
{
printf("Insert only *one* character, please\n");
exit(0);
}
for(i = 1; i <= n; i++)
{
printf("%s", argv[2]);
}
printf("\n");
}
---End of source code---
If anyone can help me, please reply.
Thanks,
SysSpider