我需要从格式化为例如"00:53:12"的字符串中提取小时,分钟和秒到变量a,b和c.
我怎么会用C来解决这个问题呢?
提前致谢!
可能重复:
如何创建一个带有"字符"的字符串?(Java)
我在java中打印这样的字符串时遇到问题我该System.out.println("this is a "test"");如何解决这个问题?
我试图将字符串的某些部分复制到其他新字符串中,但是当我尝试将其打印并打印结果时,它会给我带来奇怪的输出.我真的希望有人可以提供帮助.我有一种感觉,它是缺少指针的东西..这是我的来源;
#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); …Run Code Online (Sandbox Code Playgroud)