Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! 🚀 🔹Learn advanced coding techniques in C& C++ 🔹Master Linux internals & shell scripting 🔹Deep dive into Data Structures & Algorithms 🔹Explore Embedded Systems & Microcontrollers (8051,UART, RTOS) 🔹Get hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
Write a program to replace each string of one or more blanks by a single blank in c
Description:
- Input string:
- Pointers are sharp knives.
- Output String:
- Pointers are sharp knives.
- Blank can be spaces or tabs. (replace with single space).
- Functions
- Pointers
Objective: -
- To understand the concept of
- Functions, Arrays, and Pointers
Inputs: -
- String with multi-spaces between words
Test Case 1:
Enter the string with more spaces in between two words
Pointers are sharp knives.
Pointers are sharp knives.
Test Case 2:
Enter the string with more spaces in between two words
Welcome to Emertxe
Welcome to Emertxe
Test Case 1:Enter the string with more spaces in between two words
Welcome to india
Welcome to india
PROGRAM
---------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include<string.h>
void space(char str[])
{
int i,k=0;
while(str[k]!='\0')
{
if((str[k]==' ' && str[k+1]==' ') || (str[k]=='\t' && str[k+1]=='\t'))
{
i=k;
while(str[i]!='\0')
{
str[i]=str[i+1];
i++;
}
k--;
}
k++;
}
}
int main()
{
char str[200];
// printf("Enter the string with more spaces in between two words\n");
scanf("%[^\n]", str);
space(str);
printf("%s\n", str);
}
-------------------------------------------------------------------------------------------------------------
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment