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

  • Home
  • SEARCH
  • 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 6580125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:59:13+00:00 2026-05-25T15:59:13+00:00

I’m trying to learn C now, I’m coming from Java and there is some

  • 0

I’m trying to learn C now, I’m coming from Java and there is some stuff that is new to me.

I want to print a string and send an int and a string(char array) to another method. But I keep getting some errors that I don’t know how to fix.

Would really appreciate if someone could take their time and explain to me what’s wrong in my code. I’m quite disoriented at the moment with these pointers. When to use %s and %c when printing etc…

Code:

#include <stdio.h>

void main()
{
    int k = 10;
    char string;
    char *sptr;
    string = "hello!";  

    int *ptr;

    sptr = &string;

    ptr = &k; 
    printf("%s \n", &sptr);
    printf("Sending pointer.\n");

    sendptr(ptr, sptr);
}

And the errors.

test.c: In function ‘main’:
test.c:8:9: warning: assignment makes integer from pointer without a cast
test.c:15:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
tezt.c: In function ‘sendptr’:
tezt.c:8:8: error: incompatible types when assigning to type ‘char[6]’ from type ‘char’

Thanks for your time! 🙂

First functions solved.

Second function i get this..

tezt.c: In function ‘sendptr’:
tezt.c:5:2: error: invalid initializer



#include <stdio.h>

void sendptr(int *test, char *fname)
{
    char fnamn[] = &fname;
    int pt;


    pt = *test;
    printf("%p \n", test);
    printf("%d \n", pt); 
    printf("%s \n", fnamn);
}
  • 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-25T15:59:13+00:00Added an answer on May 25, 2026 at 3:59 pm
    char string;
    string = "hello!";  
    

    First problem: you’re declaring string as a single char, not as an array. Also, you can only initialize the array to a string literal in a single statement.

    char string[] = "hello!";
    

    Second problem: sptr is a pointer-to-char, so it has to point to the first element of your string. Either of these will do:

    char *sptr = string;
    char *sptr = &string[0];
    

    Then, when printing the string, just pass sptr directly.

    printf("%s \n", sptr);
    

    EDIT for your next question.

    char fnamn[] = &fname;
    

    You’re trying to assign a char** (pointer to pointer to char) to an array. That just won’t work. If you want to copy the string pointed to by fname into fnamn then you need to use a function such as strncpy.

    char fnamn[MAX_STRING_SIZE];
    strncpy(fnamn, fname, MAX_STRING_SIZE);
    

    Having said that, if you just want to print the string, then print fname directly without copying it into your array first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.