Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 999015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:17:13+00:00 2026-05-16T07:17:13+00:00

To make a string a null string i wrote this: #include<stdio.h> #include<conio.h> #include<string.h> int

  • 0

To make a string a null string i wrote this:

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str[15]="fahad uddin";
    strlen(str);
    puts(str);
    for(int i=0;str[i]!='\0';i++)
        strcpy(&str[i],"\0") ;
    puts(str);
    getch();
    return 0;
}

Before this i tried:

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str[15]="fahad uddin";
    strlen(str);
    puts(str);
    for(int i=0;str[i]!='\0';i++,strcpy(&str[i],"\0"))
        ;
    puts(str);
    getch();
    return 0;
}

In the first example, the program runs all right while when in the second example it prints the first letter of the string (in this example F). Why is this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:17:14+00:00Added an answer on May 16, 2026 at 7:17 am

    C strings are null-terminated. As long as you only use the functions assuming null-terminated strings, you could just zero the first character.

    str[0] = '\0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I make a JFrame like this public static void main(String[] args) { new
I want to make sure a string has only characters in this range [a-z]
Just to make this clear - what is the difference between: String(value) and value
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct dict_pair { void *key; void *value;
How to make a filter for .txt files? I wrote something like this but
I have this code: _viewModel.PhoneDefault = user == null ? : (string.IsNullOrEmpty(user.PhoneDay) ? (string.IsNullOrEmpty(user.PhoneEvening)
What is needed to make String.IsNullOrEmpty() count whitespace strings as empty? Eg. I want
Why is it that they decided to make String immutable in Java and .NET
I need to know how i can make a string like hello to Hello
I make a query: String query = SELECT DISTINCT a FROM A a FETCH

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.