C程序给出奇怪的输出

C K*_*C K 0 c arrays pointers function

我试图将字符串的某些部分复制到其他新字符串中,但是当我尝试将其打印并打印结果时,它会给我带来奇怪的输出.我真的希望有人可以提供帮助.我有一种感觉,它是缺少指针的东西..这是我的来源;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void getData(char code[], char ware[], char prod[], char qual[])
{
    printf("Bar code: %s\n", code);

    /* Copy warehouse name from barcode */
    strncpy(ware, &code[0], 3);
    ware[4] = "\0";

    strncpy(prod, &code[3], 4);
    prod[5] = "\0";

    strncpy(qual, &code[7], 3);
    qual[4] = "\0";
}

int main(){

    /* allocate and initialize strings */
    char barcode[] = "ATL1203S14";
    char warehouse[4];
    char product[5];
    char qualifier[4];

    getData(&barcode, &warehouse, &product, &qualifier);

    /* print it */
    printf("Warehouse: %s\nID: %s\nQualifier: %s", warehouse, product, qualifier);

    return 0;
 }
Run Code Online (Sandbox Code Playgroud)

编辑:

奇怪的输出是:

Bar code: ATL1203S14
Warehouse: ATL
ID: ?203(?>
Qualifier: S14u?203(?>
Run Code Online (Sandbox Code Playgroud)

cni*_*tar 6

我认为你的意思是'\0'代替"\0"3不是4:

ware[4] = "\0";
Run Code Online (Sandbox Code Playgroud)

尝试:

ware[3] = 0;
Run Code Online (Sandbox Code Playgroud)

而且&in getData(&barcode, &warehouse...)也没用.只是用getData(barcode, warehouse...);.