I m quite new to this Systems programing i know abt the system calls but what i dont get is how to write a program to swap characters in first occurrence in a text. Hope someone can help me really struggling
Asked
Active
Viewed 690 times
-3
-
You don't need system calls for that. – HAL Apr 23 '14 at 06:57
-
1Pick some book from ["The Definitive C Book Guide and List"](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) and start reading ... – Grijesh Chauhan Apr 23 '14 at 06:58
-
2Why does the title say "C program using command line"? Can you use C, or only bash commands or something? – Fantastic Mr Fox Apr 23 '14 at 06:58
-
Before system programming learn programming. Pick K&R and read it. – anurag-jain Apr 23 '14 at 13:12
1 Answers
-5
void main()
{
char a[20],b;
char *ptr;
clrscr();
printf("\n Please Give The STRING OF A : ");
scanf("%s",a);
flushall();
printf("\n Please Give The CHARACTER TO B : ");
scanf("%c",&b);
ptr = strchr(a, b);
if (ptr)
printf("The character %c is at position: %d\n", b, ptr-a+1);
else
printf("The character was not found\n");
getch();
}

DON
- 1
- 1
-
1
-
1scanf(%s) is no good choice to teach a newbee! it has no boundary-check, so buffer-overflow is possible. – Peter Miehle Apr 23 '14 at 07:07
-
Through command line how to swap characters in a text file ive been trying some code but aint working what i want is like from command line to enter the following ./a.out example.txt a (mycharacter) A(charactertoswap in textfile) – user3563273 Apr 24 '14 at 14:11
-