In C programming. write a function that accepts a string (a pointer character) and deletes all the leading spaces.
Hi,
#include <stdio.h>
char* RemoveLeadingSpaces(char* a);
int main()
{
char str1[80], *ptr;
printf("Enter a string upto 80 characters...\n");
fgets(str1, 80, stdin); //gets(str1);
ptr = RemoveLeadingSpaces(str1);
printf("String after removing leading spaces is:%s", ptr);
return 0;
}
char* RemoveLeadingSpaces(char* a)
{
int i;
while(1)
{
if(a[0] == ' ') //Comparing first character with space if it's equal copy remove first character in array.
{
for(i = 0; a[i] != '\0'; i++)
{
a[i] = a[i+1];
}
}
else //If first character is not space then exit from the loop
{
break;
}
}
return a;
}
In function i am just returning the string. If you want print in function then directly in a in function.
If you have any queries you can drop a comment....
Thanks...
In C programming. write a function that accepts a string (a pointer character) and deletes all...
[C Programming Language] Write a function that accepts a string (a pointer to a character) and deletes all the trailing spaces at the end of the string.
Write a function that accepts a pointer to a C-string as its argument. The function should count the number of times the character 'w occurs in the argument and return that number.
write a C++ function that accepts a pointer to a C-string as an argument and displays its contents backward. For instance, if the string argument is “ Gravity ” the function should display “ ytivarG ”. Demonstrate the function in a program that asks the user to input a string and then passes it to the function.
1. String Length Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function’s return value. c++
**C** Write a C function that inputs a pointer to a string and a pointer to a buffer. The function then scans through the string removing leading and trailing whitespace and replacing any run of whitespace within the string with a single space. Your function should follow this prototype: void tighten(char *oldstring, char* newstring, int length); The first argument is a pointer to a null-terminated string sitting somewhere in memory. The second argument is a pointer to the first char...
Write two versions of the function mostFrequentCharacter, one that accepts a C-string and one that accepts a string object, as its argument. The function should return the character that appears most frequently in the string. Demonstrate the function in a complete program. Do not use any string or cstring functions in the cstring version.
10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...
C++ programming language Write a program that contains following function: A function that receives a string of character, the function returns the number of letter c's or C's in the string the function receives
C++ programming language Write a program that contains following function: A function that receives a string of character, the function return true if the string contains letter c or C, otherwise, return false.
1. Write a function called deleteNode, which accepts a pointer to a list, and a pointer to the node to be deleted from the list, eg a. void deleteNode(node *head, node *delNode ); 2. Write a function called insertNode, which accepts a pointer to a list, a pointer to a new node to be inserted, and a pointer to the node after which the insertion takes place, eg a. void insertNode(node *head, node *newNode, node *prevNode );