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 8506279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:33:00+00:00 2026-06-11T02:33:00+00:00

Here is my code: printf(%s\n, test1); char c = ‘2’; char * lines[2]; char

  • 0

Here is my code:


    printf("%s\n", "test1");
    char c = '2';
    char * lines[2];
    char * tmp1 = lines[0];

    *tmp1 = c;
    printf("%s\n", "test2");

I don’t see the second printf in console.

Question: Can anybody explain me what’s wrong with my code?

NOTE: I’m trying to learn C 🙂

  • 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-06-11T02:33:02+00:00Added an answer on June 11, 2026 at 2:33 am

    This line:

    char * lines[2];
    

    declares an array of two char pointers. However, you don’t actually initialize the pointers to anything. So later when you do *tmp1 = (char)c; then you assign the character c to somewhere in memory, possibly even address zero (i.e. NULL) which is a bad thing.

    The solution is to either create the array as an array of arrays, like

    char lines[2][30];
    

    This declares lines to have two arrays of 30 characters each, and since strings needs a special terminator character you can have string of up to 29 characters in them.

    The second solution is to dynamically allocate memory for the strings:

    char *lines[2];
    lines[0] = malloc(30);
    lines[1] = malloc(30);
    

    Essentially this does the same as the above array-of-arrays declaration, but allocates the memory on the heap.

    Of course, maybe you just wanted a single string of a single character (plus the terminator), then you were almost right, just remove the asterisk:

    char line[2];  /* Array of two characters, or a string of length one */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: void subroutine(const char *message) { printf(message); } And here is
here is the c code: char **s; s[334]=strdup(test); printf(%s\n,s[334]);` i know that strdup does
Here is the code in question #include <stdio.h> struct test { unsigned char t;
See this code: int main() { char a[50]; FILE *fp; fp = fopen(test1.txt, w);
I have this code here printf '$request1 = select * from whatever where this
Here is the normal code : if(a==b) printf(equal); else if(a>b) printf(bigger); else printf(smaller); My
Just a syntax question, here is my code snippet. (Sorry, browser isn't letting me
Here is my code: #include <stdio.h> #include <stdlib.h> int main(){ int n=10; char *s=
Here's my code that is not working: print To: ; my $to=<>; chomp $to;
Here is the code: tinyMCE.init({ mode: textareas, theme: advanced, plugins: autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template, // Theme options

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.