本文整理汇总了C++中count_lines函数的典型用法代码示例。如果您正苦于以下问题:C++ count_lines函数的具体用法?C++ count_lines怎么用?C++ count_lines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_lines函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ft_read
t_map ft_read(char *filename)
{
int fd;
char *line;
char **tab;
t_index index;
t_map grid;
index.j = 0;
grid.nb_lines = count_lines(filename);
grid.tab = (int **)ft_memalloc(sizeof(int *) * count_lines(filename));
fd = open(filename, O_RDONLY);
while (get_next_line(fd, &line) > 0)
{
grid.nb_col = count_col(line); //attention ne fonctionne que pour les maps rectangle (prend la valeur de la derniere line)
grid.tab[index.j] = (int *)ft_memalloc(sizeof(int) * count_col(line));
tab = ft_strsplit(line, ' ');
index.i = 0;
while (tab[index.i])
{
grid.tab[index.j][index.i] = ft_atoi(tab[index.i]);
index.i++;
}
index.j++;
}
return (grid);
}
开发者ID:PDS42,项目名称:FdF,代码行数:27,代码来源:parsing.c
示例2: test
char test(int cur_col, int cur_line, t_lines *lines, t_pos *pos)
{
char *cur_char;
int length;
cur_char = get_pos(cur_line, cur_col, lines);
length = my_strlen(get_line(cur_line, lines)->buffer);
if (cur_line == 0 && cur_col == 0 && *cur_char != pos->top_left)
return (-1);
if (cur_line == 0 && cur_col == (length-1) && *cur_char != pos->top_right)
return (-2);
if (cur_line == count_lines(lines)-1 && cur_col == 0
&& *cur_char != pos->bottom_left)
return (-3);
if (cur_line == count_lines(lines)-1 && cur_col == (length-1)
&& *cur_char != pos->bottom_right)
return (-3);
if (cur_line > 0 && cur_line < count_lines(lines)-1 && cur_col == 0
&& *cur_char != pos->left)
return (-4);
if (cur_line > 0 && cur_line < count_lines(lines)-1
&& cur_col == (length-1) && *cur_char != pos->right)
return (-5);
return (1);
}
开发者ID:tounefr,项目名称:Piscine_C_2015,代码行数:25,代码来源:tests_pos.c
示例3: START_TEST
END_TEST
START_TEST (count_lines_test) {
int l = count_lines(
"a\n"
"sdijb\n"
"aosjfblk\n"
"alks\n"
"lkfn\n"
"kajs\n"
"nfk\n"
"lf");
ck_assert_int_eq(l, 8);
l = count_lines(
"a\n"
"sdijb\n");
ck_assert_int_eq(l, 2);
l = count_lines("a");
ck_assert_int_eq(l, 1);
}
开发者ID:Cecca,项目名称:gdem,代码行数:25,代码来源:test_parser.c
示例4: prompt_for_files
/*
* Prompts user to input paths to data files, then loads it.
*/
void prompt_for_files(){
char fname[100];
printf("Please, give a path to the file containing "
"event name, date and start time:\n ");
scanf("%s", &fname);
load_event_data(&event, fname);
printf("\nPlease, give a path to the file containing "
"nodes:\n ");
scanf("%s", &fname);
TOTAL_NODES = count_lines(fname);
nodes = load_nodes_from_file(fname);
printf("\nPlease, give a path to the file containing "
"tracks:\n ");
scanf("%s", &fname);
TOTAL_TRACKS = count_lines(fname);
tracks = load_tracks_from_file(fname);
printf("\nPlease, give a path to the file containing "
"courses:\n ");
scanf("%s", &fname);
TOTAL_COURSES = count_lines(fname);
courses = load_courses_from_file(fname);
printf("\nPlease, give a path to the file containing "
"entrants:\n ");
scanf("%s", &fname);
TOTAL_ENTRANTS = count_lines(fname);
entrants = load_entrants_from_file(fname);
}
开发者ID:kmrowiec,项目名称:runners-and-riders,代码行数:35,代码来源:main.c
示例5: parse_pos
char parse_pos(t_pos *pos, t_lines *lines)
{
int cur_line;
int return_v;
int cur_col;
int length;
cur_line = 0;
while (cur_line < count_lines(lines))
{
cur_col = 0;
length = my_strlen(get_line(cur_line, lines)->buffer);
while (cur_col < length)
{
if (count_lines(lines) > 2)
{
if (test(cur_col, cur_line, lines, pos) <= 0)
return (0);
}
cur_col = cur_col + 1;
}
cur_line = cur_line + 1;
}
return (1);
}
开发者ID:tounefr,项目名称:Piscine_C_2015,代码行数:25,代码来源:tests_pos.c
示例6: wxT
wxString pgsRecord::value() const
{
wxString data;
pgsVarMap vars;
// Go through each line and enclose it into braces
for (USHORT i = 0; i < count_lines(); i++)
{
data += wxT("(");
// Go through each column and separate them with commas
for (USHORT j = 0; j < count_columns(); j++)
{
wxString elm(m_record[i][j]->eval(vars)->value());
if (!m_record[i][j]->is_number())
{
elm.Replace(wxT("\\"), wxT("\\\\"));
elm.Replace(wxT("\""), wxT("\\\""));
elm = wxT("\"") + elm + wxT("\"");
}
data += elm + (j != count_columns() - 1 ? wxT(",") : wxT(""));
}
data += (i == count_lines() - 1) ? wxT(")") : wxT(")\n");
}
// Return the string representation of the record
return data;
}
开发者ID:kleopatra999,项目名称:pgadmin3,代码行数:29,代码来源:pgsRecord.cpp
示例7: main
int main(int argc,char *argv[]){
int i=0;
srand(time(NULL));
net mlpnet;
int layer_neurons[]={2,10,5,1};
char sigmods[]={'l','l','l','l'};
init_net(&mlpnet,4,layer_neurons,sigmods);
float *inputs=(float*)malloc(sizeof(float)*2);
sample *samples;
int num_lines=count_lines(argv[1]);
samples=(sample*)malloc(sizeof(sample)*num_lines);
read_samples(argv[1],samples,num_lines);
train(&mlpnet,num_lines,samples,EPOCHS);
free_samples(samples,num_lines);
//==================================================
num_lines=count_lines(argv[2]);
sample *test_samples=(sample*)malloc(sizeof(sample)*num_lines);
read_samples(argv[2],test_samples,num_lines);
float *scores=(float*)malloc(sizeof(float)*num_lines);
predict(&mlpnet,num_lines,test_samples,scores);
free_samples(test_samples,num_lines);
free_net(&mlpnet,4,layer_neurons);
char scorefile[100];
sprintf(scorefile,"%s.score",argv[1]);
FILE *score=fopen(scorefile,"w");
for(i=0;i<num_lines;i++)
{
fprintf(score,"%f\n",scores[i]);
}
fclose(score);
return 0;
}
开发者ID:minority1728645,项目名称:mlp,代码行数:50,代码来源:mlp.c
示例8: do_refresh
void do_refresh()
{
int count = 0;
char wrap_output[STRING_LENGTH];
int L;
int i;
for (i = 0; i < HISTORY; i++) {
wrap(wrap_output, lines[i], x);
L = count_lines(wrap_output);
count = count + L;
if (count < y) {
move(y - 1 - count, 0);
printw(wrap_output);
clrtoeol();
}
}
move(y - 1, 0);
clrtoeol();
printw(">> ");
printw(line);
clrtoeol();
refresh();
}
开发者ID:1100110,项目名称:ProjectTox-Core,代码行数:26,代码来源:nTox.c
示例9: parse_file
extern void parse_file(char *CONFIG_FILE_PATH, char **PARSED_LINES){
char *line;
FILE *CONFIG_FILE;
ssize_t read;
size_t len = 0;
int lines = 0;
int number_of_lines = 0;
CONFIG_FILE = fopen(CONFIG_FILE_PATH, "r");
lines = count_lines(CONFIG_FILE);
while((read = getline(&line, &len, CONFIG_FILE)) != -1){
PARSED_LINES[number_of_lines] = malloc(strlen(line)*sizeof(char));
snprintf(PARSED_LINES[number_of_lines], strlen(line), "%s", line);
number_of_lines++;
}
// cleanup
fclose(CONFIG_FILE);
free(line);
}
开发者ID:knkp,项目名称:IRC_Project,代码行数:27,代码来源:terminal_Server.c
示例10: marked_message_internal
static void
marked_message_internal (char *msg, int mark_start, int mark_end)
{
rp_screen *s = current_screen ();
int num_lines;
int width;
int height;
PRINT_DEBUG (("msg = %s\n", msg?msg:"NULL"));
PRINT_DEBUG (("mark_start = %d, mark_end = %d\n", mark_start, mark_end));
/* Calculate the width and height of the window. */
num_lines = count_lines (msg, strlen(msg));
width = defaults.bar_x_padding * 2 + max_line_length(msg);
height = FONT_HEIGHT (s) * num_lines + defaults.bar_y_padding * 2;
prepare_bar (s, width, height, num_lines > 1 ? 1 : 0);
if (defaults.bar_sticky)
/* Sticky bar is only showing the current window title, don't mark it */
mark_start = mark_end = -1;
else
{
/* Draw the mark over the designated part of the string. */
correct_mark (strlen (msg), &mark_start, &mark_end);
draw_mark (s, msg, mark_start, mark_end);
}
draw_string (s, msg, mark_start, mark_end);
/* Keep a record of the message. */
update_last_message (msg, mark_start, mark_end);
}
开发者ID:devanstroud,项目名称:ratpoison,代码行数:33,代码来源:bar.c
示例11: deltafile_init_strbuf
int deltafile_init_strbuf(struct deltafile *df, struct strbuf *buf, char delim)
{
size_t lines = count_lines(buf);
deltafile_init(df, lines + 1, delim);
df->size = split_in_place(&df->file, df->arr, delim);
return 0;
}
开发者ID:dilraj45,项目名称:pegit,代码行数:7,代码来源:delta-file.c
示例12: do_refresh
void do_refresh()
{
int count = 0;
char wrap_output[STRING_LENGTH_WRAPPED];
int i;
for (i = 0; i < HISTORY; i++) {
if (flag[i])
wrap_bars(wrap_output, lines[i], x);
else
wrap(wrap_output, lines[i], x);
int L = count_lines(wrap_output);
count = count + L;
if (count < y) {
move(y - 1 - count, 0);
printw("%s", wrap_output);
clrtoeol();
}
}
move(y - 1, 0);
clrtoeol();
printw(">> ");
printw("%s", input_line);
clrtoeol();
refresh();
}
开发者ID:AndreasDriesen,项目名称:toxcore,代码行数:29,代码来源:nTox.c
示例13: send_request
void send_request (int socket_fd, char *cmd, int argc, char *argv[], char* dir, char* classpath)
{
// Send request type byte:
unsigned char type[1] = {CMD_REQ};
if ( write(socket_fd, type, 1) != 1 )
error("Failes to send request type byte to server: %s", error_msg());
// Open stream for writing to server:
FILE *socket_in = fdopen(socket_fd, "w");
if ( socket_in == NULL )
error("Failed to create i/o stream for writing to server: %s", error_msg());
// Write request to stream:
fprintf(socket_in, "pid\n%i\n\n", getpid());
fprintf(socket_in, "cmd\n%s\n\n", cmd);
fprintf(socket_in, "argc\n%i\n\n", argc);
if ( argv != NULL )
{
int i;
for (i = 0; i < argc; i++)
fprintf(socket_in, "arg\n%i\n%s\n\n", count_lines(argv[i]), argv[i]);
}
fprintf(socket_in, "dir\n%s\n\n", dir);
if ( classpath != NULL )
fprintf(socket_in, "classpath\n%s\n\n", classpath);
fprintf(socket_in, "start\n\n");
fflush(socket_in);
}
开发者ID:TU-Berlin,项目名称:Mumie,代码行数:28,代码来源:mmjvmc.c
示例14: wc
void wc(FILE *ofile, FILE *infile, char *inname) {
char *code;
int c;
size_t n = 0;
code = malloc(1000);
int char_count = 0;
int line_count = 0;
int word_count = 0;
char path[1024];
char result[1024];
int fd = fileno(ofile);
while ((c = fgetc(ofile)) != EOF)
{
code[n++] = (char) c;
}
code[n] = '\0';
char_count = count_characters(code);
line_count = count_lines(code);
word_count = count_words(code);
sprintf(path, "/proc/self/fd/%d",fd);
memset(result, 0, sizeof(result));
readlink(path, result, sizeof(result)-1);
printf(" %d\t%d\t%d\t%s\t%s\n", line_count, word_count, char_count, result, path);
}
开发者ID:sriking1783,项目名称:cs162,代码行数:27,代码来源:wc.c
示例15: calc_vlines_wrapped
/* Recalculates virtual lines of a view with line wrapping. */
static void
calc_vlines_wrapped(void)
{
const char *p;
char *q;
int i;
const int nlines = count_lines(text, INT_MAX);
data = reallocarray(NULL, nlines, sizeof(*data));
nvlines = 0;
p = text;
q = text - 1;
for(i = 0; i < nlines; ++i)
{
char saved_char;
q = until_first(q + 1, '\n');
saved_char = *q;
*q = '\0';
data[i][0] = nvlines++;
data[i][1] = utf8_strsw_with_tabs(p, cfg.tab_stop);
data[i][2] = p - text;
nvlines += data[i][1]/viewport_width;
*q = saved_char;
p = q + 1;
}
}
开发者ID:lowtalker,项目名称:vifm,代码行数:33,代码来源:more.c
示例16: encode
int encode (FILE *fdsrc, FILE *fdtgt, FILE *fdcfg, FILE *fdkey)
{
int *configvalues = 0;
int lines = 0;
int error = 0;
printf ("[INFO] ... Start encoding...\n");
// count lines in the read files
lines = count_lines (fdsrc);
if (lines < 0)
{
printf ("[ERROR] ... Unable to count lines in file...\n");
return -1;
}
printf ("[INFO] ... Read %d lines in source file...\n", lines);
configvalues = malloc (sizeof(int)*lines);
if (configvalues == NULL)
{
printf ("[ERROR] ... Unable to allocate memory for config values...\n");
return -1;
}
// interpret values
error = interpret_config_values (fdsrc, configvalues, lines);
if (error != 0)
{
printf ("[ERROR] ... Unable to interpret config values...\n");
return -1;
}
return 0;
}
开发者ID:20logTom,项目名称:otp,代码行数:35,代码来源:otp.c
示例17: count_lines
/*
count how many lines in a number of files
input: vector of filenames
output: number of lines
*/
int count_lines(const vector<string>& files) {
int total = 0;
for (size_t i = 0; i < files.size(); ++i) {
total += count_lines(files[i]);
}
return total;
}
开发者ID:mye6,项目名称:qFinance,代码行数:12,代码来源:Utility.cpp
示例18: doeclim_load_calibration
//=========================================================================
//
// void doeclim_load_calibration(DICE *dice)
//
// Loads a file containing the calibration results. File should have 3
// columns (cs, kv, alpha).
//
// Input parameters:
// *dice = pointer to DICE object
//
//=========================================================================
void doeclim_load_calibration(DICE *dice)
{
// Calibration file name
const char calfile[] = "calibration_results.txt";
// Find the number of calibration data points from file
int n = 0;
count_lines(calfile, &n);
dice->clim.n_calpoints = n;
// Open the file and read in the calibration data
FILE * fp;
fp = fopen(calfile, "r");
int counter = 0;
float this_cs, this_kv, this_alpha;
while(!feof(fp)) {
if (fscanf(fp, "%g %g %g", &this_cs, &this_kv, &this_alpha) != 3) {
break;
}
dice->clim.cs_cal[counter] = this_cs;
dice->clim.kv_cal[counter] = this_kv;
dice->clim.alpha_cal[counter] = this_alpha;
counter++;
if (counter >= n) {
break;
}
}
fclose(fp);
}
开发者ID:scrim-network,项目名称:cdice_doeclim,代码行数:42,代码来源:CDICE_doeclim.cpp
示例19: set_crash
char *pl02x100_get_word(char *aword)
{
FILE *fp;
char filename[250];
int lines,cnt,i;
set_crash();
lines=cnt=i=0;
sprintf(filename,"%s/%s", PLFILES, PL02x100_DICT);
lines=count_lines(filename);
srand(time(0));
cnt=rand()%lines;
if (!(fp=fopen(filename,"r"))) return(PL02x100_DEFWORD);
fscanf(fp,"%s\n",aword);
while (!feof(fp)) {
if (i==cnt) {
fclose(fp);
return aword;
}
++i;
fscanf(fp,"%s\n",aword);
}
fclose(fp);
/* if no word was found, just return a generic word */
return(PL02x100_DEFWORD);
}
开发者ID:Lopo,项目名称:Lotos,代码行数:26,代码来源:hangman.c
示例20: get_hang_word
/*
* returns a word from a list for hangman.
* this will save loading words into memory, and the list could be updated as and when
* you feel like it
*/
void
get_hang_word(char *aword)
{
char filename[80];
FILE *fp;
int cnt, f;
/* if no word is found, just return a generic word */
strcpy(aword, "hangman");
sprintf(filename, "%s/%s", MISCFILES, HANGDICT);
cnt = count_lines(filename);
if (!cnt) {
return;
}
fp = fopen(filename, "r");
if (!fp) {
return;
}
cnt = rand() % cnt;
for (f = fscanf(fp, "%s\n", aword); f == 1; f = fscanf(fp, "%s\n", aword)) {
if (!cnt--) {
break;
}
}
fclose(fp);
}
开发者ID:BackupTheBerlios,项目名称:mamnuts,代码行数:31,代码来源:games.c
注:本文中的count_lines函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论