LoadRunner version 12.5
OS: Windows 7

what am i doing wrong in the file operation part?? It is not creating the file. I have tried to put the file path in c drive as well as d drive, as well as 2 or 3 levels deep folder structure. but somehow the file is not getting created,

All the values that i am trying to put in the file are getting generated properly, as you can see i have used lr output message to print them out and check them.

include <stdio.h>
Action()
{

int i;
int imax;
int rand1;
char newVarName[500];
FILE* file_stream;
char * filename = "d:\\RouteDetails.txt";

web_set_sockets_option("SSL_VERSION", "2&3");

web_set_max_html_param_len("32000");


web_set_user("CTS.COM\\180937",
lr_unmask("5a2f9911b093f34e3f8ca40aa7064d"),
"transport.xyz.com:443");

lr_start_transaction("Launch");

web_url("transport.xyz.com",
"URL=https://transport.xyz.com/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t3.inf",
"Mode=HTML",
EXTRARES,
"Url=/IMAGES/banner_bg.jpg",
"Referer=https://transport.xyz.com/AssociateHome.aspx", ENDITEM,
LAST);

lr_end_transaction("Launch",LR_AUTO);

lr_think_time(3);

//************************************************** ************************************************** ******

lr_start_transaction("searchSchedule");

web_reg_save_param_attrib(
"ParamName=__VIEWSTATEGENERATOR",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATEGENERATOR",
"Id=__VIEWSTATEGENERATOR",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);
web_reg_save_param_attrib(
"ParamName=__VIEWSTATE",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATE",
"Id=__VIEWSTATE",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_reg_save_param_attrib(
"ParamName=__EVENTVALIDATION",
"TagName=input",
"Extract=value",
"Name=__EVENTVALIDATION",
"Id=__EVENTVALIDATION",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);


web_link("Search Schedule",
"Text=Search Schedule",
"Ordinal=1",
"Snapshot=t4.inf",
EXTRARES,
"Url=/WebResource.axd?
d=rcIyG2OcW8Jw0dVKAHKouB_qi7orHpXPRHHowC57SH37biy2 txFUrKGEIgh8UEtEt0jJ-
7enVMK28-Wwz3rF2yEmfcDrzHeufqr4EpqK9Wo1&t=63541842426000000 0", ENDITEM,
"Url=/WebResource.axd?
d=hJgAHOWKmtlJ94s8P0gxTiQFUJpgzvWtwuVazXJ6sglaRQpq xuuT_S8s8fI7pyvl9Ckw2lX8f
1RaAi6-WLJEDtCkNXEaqZWMG0FmPRYC9oQ1&t=635418424260000000" , ENDITEM,
"Url=/Images/home_icon.jpg", ENDITEM,
"Url=/IMAGES/ss_ord.gif", ENDITEM,
"Url=/IMAGES/ms_over.gif", ENDITEM,
"Url=/IMAGES/ts_ord.gif", ENDITEM,
"Url=/IMAGES/rls_ord.gif", ENDITEM,
"Url=/IMAGES/es_ord.gif", ENDITEM,
LAST);

lr_end_transaction("searchSchedule",LR_AUTO);

//************************************************** ************************

lr_start_transaction("select boardingPoint");

web_url("GetBoardingPoints.aspx",
"URL=https://transport.xyz.com/GetBoardingPoints.aspx?
id=BoardingPoint_idMs&name=txtBoardingpointNameMs& city_id=1",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);

lr_end_transaction("select boardingPoint",LR_AUTO);

//************************************************** ************************

lr_start_transaction("Search1");



web_reg_save_param_attrib(
"ParamName=__VIEWSTATEGENERATOR",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATEGENERATOR",
"Id=__VIEWSTATEGENERATOR",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);
web_reg_save_param_attrib(
"ParamName=__VIEWSTATE",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATE",
"Id=__VIEWSTATE",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_reg_save_param_attrib(
"ParamName=__EVENTVALIDATION",
"TagName=input",
"Extract=value",
"Name=__EVENTVALIDATION",
"Id=__EVENTVALIDATION",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);



web_reg_save_param("RouteNo", "LB=<a href='javascript:OpenRouteMap(",
"RB=,", LAST); ////<a href='javascript:OpenRouteMap(

web_submit_data("SearchService.aspx",
"Action=https://transport.xyz.com/SearchService.aspx",
"Method=POST",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/SearchService.aspx",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=__EVENTTARGET", "Value=", ENDITEM,
"Name=__EVENTARGUMENT", "Value=", ENDITEM,
"Name=__LASTFOCUS", "Value=", ENDITEM,
"Name=__VIEWSTATE", "Value={__VIEWSTATE}", ENDITEM,
"Name=__VIEWSTATEGENERATOR", "Value={__VIEWSTATEGENERATOR}", ENDITEM,
"Name=__EVENTVALIDATION", "Value={__EVENTVALIDATION}", ENDITEM,
"Name=ddlCityMs", "Value=1", ENDITEM,
"Name=txtBoardingpointNameMs", "Value=Adyar Depot", ENDITEM,
"Name=ddlMsEndLocation", "Value=135", ENDITEM,
"Name=btnMsSearch", "Value=Search", ENDITEM,
"Name=BoardingPoint_idMs", "Value=358", ENDITEM,
"Name=BoardingPoint_idEs", "Value=", ENDITEM,
EXTRARES,
"URL=/IMAGES/ts_ord_over.gif", ENDITEM,
LAST);

lr_end_transaction("Search1",LR_AUTO);
lr_think_time(3);

//************************************************** ***********

lr_start_transaction("GotoTimeBasedSearchTab");

web_reg_save_param_attrib(
"ParamName=__VIEWSTATEGENERATOR",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATEGENERATOR",
"Id=__VIEWSTATEGENERATOR",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);
web_reg_save_param_attrib(
"ParamName=__VIEWSTATE",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATE",
"Id=__VIEWSTATE",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_reg_save_param_attrib(
"ParamName=__EVENTVALIDATION",
"TagName=input",
"Extract=value",
"Name=__EVENTVALIDATION",
"Id=__EVENTVALIDATION",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_submit_data("SearchService.aspx_2",
"Action=https://transport.xyz.com/SearchService.aspx",
"Method=POST",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/SearchService.aspx",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=__EVENTTARGET", "Value=", ENDITEM,
"Name=__EVENTARGUMENT", "Value=", ENDITEM,
"Name=__LASTFOCUS", "Value=", ENDITEM,
"Name=__VIEWSTATE", "Value={__VIEWSTATE}", ENDITEM,
"Name=__VIEWSTATEGENERATOR", "Value={__VIEWSTATEGENERATOR}", ENDITEM,
"Name=__EVENTVALIDATION", "Value={__EVENTVALIDATION}", ENDITEM,
"Name=ddlCityMs", "Value=1", ENDITEM,
"Name=txtBoardingpointNameMs", "Value=Adyar Depot", ENDITEM,
"Name=ddlMsEndLocation", "Value=135", ENDITEM,
"Name=BoardingPoint_idMs", "Value=358", ENDITEM,
"Name=BoardingPoint_idEs", "Value=", ENDITEM,
"Name=ibts.x", "Value=131", ENDITEM,
"Name=ibts.y", "Value=10", ENDITEM,
EXTRARES,
"URL=/IMAGES/ms_ord.gif", ENDITEM,
"URL=/IMAGES/ts_over.gif", ENDITEM,
LAST);

web_reg_save_param_attrib(
"ParamName=__VIEWSTATEGENERATOR",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATEGENERATOR",
"Id=__VIEWSTATEGENERATOR",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);
web_reg_save_param_attrib(
"ParamName=__VIEWSTATE",
"TagName=input",
"Extract=value",
"Name=__VIEWSTATE",
"Id=__VIEWSTATE",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_reg_save_param_attrib(
"ParamName=__EVENTVALIDATION",
"TagName=input",
"Extract=value",
"Name=__EVENTVALIDATION",
"Id=__EVENTVALIDATION",
"Type=hidden",
SEARCH_FILTERS,
"IgnoreRedirections=No",
"RequestUrl=*/SearchService.aspx*",
LAST);

web_submit_data("SearchService.aspx_3",
"Action=https://transport.xyz.com/SearchService.aspx?param_id=5",
"Method=POST",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/SearchService.aspx",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=__EVENTTARGET", "Value=ddlTsStartLocation", ENDITEM,
"Name=__EVENTARGUMENT", "Value=", ENDITEM,
"Name=__LASTFOCUS", "Value=", ENDITEM,
"Name=__VIEWSTATE", "Value={__VIEWSTATE}", ENDITEM,
"Name=__VIEWSTATEGENERATOR", "Value={__VIEWSTATEGENERATOR}", ENDITEM,
"Name=__EVENTVALIDATION", "Value={__EVENTVALIDATION}", ENDITEM,
"Name=ddlCityTs", "Value=1", ENDITEM,
"Name=ddlTsStartLocation", "Value=135", ENDITEM,
"Name=BoardingPoint_idMs", "Value=", ENDITEM,
"Name=BoardingPoint_idEs", "Value=", ENDITEM,
LAST);
lr_end_transaction("GotoTimeBasedSearchTab",LR_AUT O);

//********************

lr_think_time(3);


//****************************

lr_start_transaction("Search_TimeBased");


web_reg_save_param("RouteDetail", "LB=<td align=\"left\">", "RB=</td",
"ORD=ALL", LAST);

web_submit_data("SearchService.aspx_4",
"Action=https://transport.xyz.com/SearchService.aspx?param_id=5",
"Method=POST",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/SearchService.aspx?param_id=5",
"Snapshot=t9.inf",
"Mode=HTML",
ITEMDATA,
"Name=__EVENTTARGET", "Value=", ENDITEM,
"Name=__EVENTARGUMENT", "Value=", ENDITEM,
"Name=__LASTFOCUS", "Value=", ENDITEM,
"Name=__VIEWSTATE", "Value={__VIEWSTATE}", ENDITEM,
"Name=__VIEWSTATEGENERATOR", "Value={__VIEWSTATEGENERATOR}", ENDITEM,
"Name=__EVENTVALIDATION", "Value={__EVENTVALIDATION}", ENDITEM,
"Name=ddlCityTs", "Value=1", ENDITEM,
"Name=ddlTsStartLocation", "Value=135", ENDITEM,
"Name=ddlTsTime", "Value=ALL", ENDITEM,
"Name=btnTsList", "Value=Search", ENDITEM,
"Name=BoardingPoint_idMs", "Value=", ENDITEM,
"Name=BoardingPoint_idEs", "Value=", ENDITEM,
LAST);

lr_end_transaction("Search_TimeBased",LR_AUTO);

file_stream = fopen(filename, "w");

imax= atoi(lr_eval_string("{RouteDetail_count}"));
lr_output_message("count is %d", imax);

for(i=1;i<=imax;i++) {

sprintf(newVarName, "{RouteDetail_%d}", i);
lr_output_message("string is %s", newVarName);

lr_save_string(lr_eval_string(newVarName), "stringtowrite");

fprintf(file_stream,"%s,\n", lr_eval_string("{stringtowrite}"));

}

fclose(file_stream);

//****************************

lr_think_time(3);

lr_start_transaction("ClickRoute");

web_url("ShowRouteMap.aspx",
"URL=https://transport.xyz.com/ShowRouteMap.aspx?RouteNo={RouteNo}",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t10.inf",
"Mode=HTML",
LAST);

lr_end_transaction("ClickRoute",LR_AUTO);

lr_think_time(3);
//***************************

lr_start_transaction("GoHome1");

web_url("AssociateHome.aspx",
"URL=https://transport.xyz.com/AssociateHome.aspx",
"Resource=0",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/SearchService.aspx?param_id=5",
"Snapshot=t11.inf",
"Mode=HTML",
LAST);

lr_end_transaction("GoHome1",LR_AUTO);

lr_think_time(3);
//*****************************
for (i=1; i<=5; i++){


lr_start_transaction("SMSShortCodeList");

web_reg_save_param("RandomLetter", "LB=aspx?Letter=", "RB=&", "ORD=ALL",
LAST); //.aspx?Letter=A&

web_link("Short Code list",
"Text=Short Code list",
"Snapshot=t12.inf",
EXTRARES,
"Url=/IMAGES/BPHELP.bmp", ENDITEM,
LAST);

lr_end_transaction("SMSShortCodeList",LR_AUTO);

lr_think_time(3);

//***************************

lr_start_transaction("ClickALetter");


rand1 = (rand() % atoi(lr_eval_string("{RandomLetter_count}")) + 1);
//Find out a rand no between 1 and count
sprintf(newVarName, "{RandomLetter_%d}", rand1);
lr_output_message("newVarName is %s", lr_eval_string(newVarName));
lr_save_string(lr_eval_string(newVarName), "newRandLetter");


web_url("BoardingPtShortCodeDisplay.aspx",
"URL=https://transport.xyz.com/BoardingPtShortCodeDisplay.aspx?Letter=
{newRandLetter}&City=1",
"Resource=0",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/BoardingPtShortCodeDisplay.aspx",
"Snapshot=t13.inf",
"Mode=HTML",
LAST);

lr_end_transaction("ClickALetter",LR_AUTO);

lr_think_time(3);

}

//end For loop

//******************************

lr_start_transaction("GoHome2");

web_url("AssociateHome.aspx_2",
"URL=https://transport.xyz.com/AssociateHome.aspx",
"Resource=0",
"RecContentType=text/html",
"Referer=https://transport.xyz.com/BoardingPtShortCodeDisplay.aspx?
Letter=R&City=1",
"Snapshot=t14.inf",
"Mode=HTML",
LAST);

lr_end_transaction("GoHome2",LR_AUTO);

lr_think_time(3);
//************************************************** ************************************************** ******

lr_start_transaction("Logout");

web_link("Logout",
"Text=Logout",
"Snapshot=t15.inf",
LAST);

lr_end_transaction("Logout",LR_AUTO);
//****************************

return 0;
}