strcpy

No instance of overloaded function “strcpy_s” matches the argument list

淺唱寂寞╮ 提交于 2019-12-12 03:38:04
问题 For some reason a char cant go in strcopy_s();... #include <iostream> #include <cstring> using namespace std; struct DATE { int year; int month; int date; }; struct Book { char name[50]; char author[50]; int id; DATE date; }; int main() { Book book1; DATE date1; char bookName, bookAuthor; int date, year, month; cout << "Date Of Publishing? " << endl; cin >> date; cout << "Month Of Publishing?" << endl; cin >> month; cout << "Year Of Publishing?" << endl; cin >> year; date1.year = year; date1

Why is reading from file function crashing?

假装没事ソ 提交于 2019-12-11 15:25:03
问题 Trying to read multiple line from file to store them in a structure made up of the string elements, however when I run the program it simply crashes and I haven't the faintest idea why. function in question: Hashtbl* loadfromfile(Hashtbl* hashtbl, char *path){ int i = 0; char line[100]; char* string[40]; FILE *f = fopen(path, "r"); if(f == NULL){ printf("FILE NO FOUND!"); }else{ while(fgets(line, sizeof(line), f)!=NULL){ strcpy(string[i],line); i++; } fclose(f); for(i = 0; i<(SIZE*2); i++){

What is the difference between strcpy and “=”? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-11 08:31:02
问题 This question already has answers here : C - why is strcpy() necessary (4 answers) Closed 2 years ago . I would like to know if there is a difference between char* test = "test" and strcpy(test, "test") , and if there is one, what is this difference. Thanks. 回答1: The strcpy function ( which you should never use! -- use strncpy or strdup to avoid buffer overflow vulnerabilities), copies the bytes from one string buffer to the other; assignment changes the buffer to which you are pointing. Note

Strings and string functions in C

折月煮酒 提交于 2019-12-11 04:18:45
问题 I wrote the following: #include <stdio.h> #include <string.h> char* getString(); char* getString(){ char str[10]; gets(str); return str; } int main() { char* s; s=getString(); strcpy(s,"Hi"); puts(s); return 0; } I know that the length of str must be less than 10, but even when I wrote just "Hi", nothing was being printed. as far as I see it, it should be Ok. the compiler says that fgets is dangerous and should not be used . What is the reason that nothing being printed on the screen? 回答1:

strcpy and printf a multidimensional char array C

我只是一个虾纸丫 提交于 2019-12-11 02:24:20
问题 Say I have an array char messages[10][2][50]; What is the correct syntax for strcpy, in order to get the data into one of the strings (inner most char array of size 50) and then the corresponding convention to supply it to printf via %s? For that matter, am I declaring the array subscripts in the correct order? It is intended to be 10 lots of, pairs (of 2) strings. Each string being 50 chars wide. 01{{50 chars},{50 chars}} 02{{50 chars},{50 chars}} ... 09{{50 chars},{50 chars}} 10{{50 chars},

strcpy behaving differently on ios7

百般思念 提交于 2019-12-10 18:24:32
问题 IOS7 seems to come with a new implementation (optimisation maybe) of strings strcpy. Before I was able to copy strings from any position of the array but now if I start copying from any position where (i % 4 != 0) it will crash. To show this I ran this code both in iOS6 and 7, and it crashed the app on 7: char *x = malloc(1024); strcpy(x, "hello world"); char *x2 = x + 1; strcpy(x, x2); what am I doing wrong? 回答1: The C11 standard says at §7.24.2.3: The strcpy function copies the string

strcpy string array

落爺英雄遲暮 提交于 2019-12-10 17:32:04
问题 char copy, array[20] printf("enter ..."): scanf("%s", array); if (strlen(array) > 20 ) { strcpy(copy, array....); what would I need to do to make it only grab the first 20 character if the input is more then 20 character long 回答1: Use strncpy instead of strcpy . That's all there is to it. (Caution: strncpy does not nul-terminate the destination string if it hits its limit.) EDIT: I didn't read your program carefully enough. You lose already at the scanf call if user input is longer than 20

Structures in C with “no member named…” error

≡放荡痞女 提交于 2019-12-10 15:58:42
问题 I'm trying to create a struct which contains the country, state, city and the name of a local shop. Unfortunately, I get this error: No member named bavaria in struct country So it seems that the error occurs here: strcpy(germany.bavaria.ingolstadt.westpark, "Westpark"); What am I doing wrong? This is my complete code: #include <stdio.h> #include <string.h> int main() { struct country { char countryname[100]; struct state { char statename[100]; struct city { char cityname[100]; int postal;

C语言课设-单位车辆调度管理

不羁岁月 提交于 2019-12-10 07:16:46
单位车辆信息包括:车牌号、车型、载重(客)量,车牌,生产厂家,出厂日期,购买日期,购买单价等;车辆调度信息还应包括:用车人,用车单位,调度人,出车车牌,出车司机,出车用途,出车日期,出车时间,收车日期,收车时间及出车费用等信息等。设计“车辆调度管理系统”,使之能提供以下功能: 系统以菜单方式工作; 车辆调度信息录入功能(车辆调度信息用文件vehicle.txt保存); 车辆信息及车辆调度信息浏览功能; 车辆调度查询和排序功能: 车辆信息及车辆调度信息的删除与修改等功能。 代码如下,完全原创,代码功能完整!! #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> int feature;//定义输入的功能选项 char now_date[12];//定义系统当前日期存储缓冲区 SYSTEMTIME sys; //定义系统时间变量 //定义车辆数据结构 typedef struct Vehicle { char *ver_id;//定义车辆编号 char *ver_no;//定义车辆牌号 char *weight;//定义车辆对应载重量 char *ver_trand;//定义车牌 char *factory;//定义车辆生产厂家 char *outdate;//定义车辆出厂日期

Why no sanity checks in legacy strcpy()

有些话、适合烂在心里 提交于 2019-12-10 02:09:37
问题 Following is the most popular implementation of strcpy in traditional systems. Why dest and src are not checked for NULL in the start? I heard once that in old days the memory was limited so short code was always preferred. Will you implement strcpy and other similar functions with NULL pointer checks at the start now days? Why not? char *strcpy(char *dest, const char *src) { char *save = dest; while(*dest++ = *src++); return save; } 回答1: NULL is a bad pointer, but so is (char*)0x1 . Should